Library Making Sound Undeclared

WolfieeifloW

WEHZ Helper
Reaction score
372
I changed the "scope" in my trigger to a "library" and now I get the error:
"Undeclared variable gg_snd_Feedback".
Here's the code I have (shortened to show the main parts);
JASS:
library ArmorCrush initializer Init

globals
    private constant sound crushSound = gg_snd_Feedback
    // Sound played by Armor Crush (NOTE: You must import the sound via Sound Editor)
endglobals

endlibrary

I have the sound imported in the Sound Editor.
I tried changing my library back to a scope and the sound didn't give an error.
So how do I make it not error in a library?

Thanks in advance TH.net!

EDIT: Even in a scope, the sound doesn't play, why :( ?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Sound variables are globals too...

I'd put "set mySoundVar = globalSoundVar" in some trigger running on "elapsed time is 0.0 seconds".
At that point you're sure all globals are set.
(It might still not work, but that's another story :p)
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Is there no other way to do it besides making another trigger?

EDIT: I don't know how to set it either :confused: .
In GUI or JASS?
Where and how?

I'd prefer to have it all in one trigger :eek: .
 

Flare

Stops copies me!
Reaction score
662
Well, you could do
JASS:
globals
  sound SpellSoundEffect = null
endglobals

...

function SpellActions takes nothing returns nothing
//locals
  if SpellSoundEffect == null then
    set SpellSoundEffect = gg_sound_YourSound
  endif
//more stuff
endfunction

then the sound will be initialized with first spell cast

Very minor drop in efficiency (since the check is done every spellcast), but it's much more convienient than additional triggers and functions in your code. It's much more practical, and unless you're an efficiency freak, it won't make much difference - at any rate, nobody will notice it ingame
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Ok, I've got:
JASS:
globals
    private sound crushSnd = null
endglobals

function...
    ...
    if crushSnd == null then
        set crushSnd = gg_snd_Feedback
    endif
    ...
endfunction

However, I want to declare the name of the sound in the globals section to make it easily customizable for people who download my spell.
Could I maybe set "gg_snd_Feedback" into a string variable in globals?
Like this:
JASS:
globals
    private sound crushSnd = null
    private constant string crushSound = gg_snd_Feedback
endglobals

function...
    ...
    if crushSnd == null then
        set crushSnd = crushSound
    endif
    ...
endfunction

:eek: ?

EDIT: Nevermind, you can't convert a string to a sound it says...
How would I make the sound customizable in the globals still though?



EDITEDIT: I've changed my spell back to a scope.
Here's the code:
JASS:
// +------------------------------------------------------------+
// |                                                            |
// |               -=-=- Armor Crush [v1.0] -=-=-               |
// |                -=-=- By Wolfie[NoCT] -=-=-                 |
// |                    Requires Jass NewGen                    |
// |                                                            |
// +------------------------------------------------------------+
// |                                                            |
// |   Gives a 15% chance to deal a portion of your             |
// |      health back at the attacker. This blow is so          |
// |         shocking it also reduces the attackers armor.      |
// |                                                            |
// +------------------------------------------------------------+
// |                                                            |
// |   -=-=- How To Implement -=-=-                             |
// |      1. Copy this trigger into your map                    |
// |      2. Copy the buffs into your map                       |
// |      3. Copy the abilities into your map                   |
// |      4. Copy the dummies into your map                     |
// |      5. Make sure the 'Rawcodes' in the trigger match      |
// |            your buffs/abilities/units in Object Editor     |
// |      6. Customize the spell                                |
// |      7. Enjoy!                                             |
// |                                                            |
// +------------------------------------------------------------+
// |                                                            |
// |   -=-=- Credits -=-=-                                      |
// |      Credits are not needed, but appreciated               |
// |         Just don't claim this as yours                     |
// |                                                            |
// +------------------------------------------------------------+
// |   -=-=- Version History -=-=-                              |
// |                                                            |
// |      Version 1.0                                           |
// |         - Initial release                                  |
// |                                                            |
// +------------------------------------------------------------+

scope ArmorCrush initializer Init

// +-------------------------------------+
// |       -=-=- MODIFY HERE -=-=-       |
// |       -=-=- MODIFY HERE -=-=-       |
// |       -=-=- MODIFY HERE -=-=-       |
// +-------------------------------------+

globals
    private constant integer ability_ACid = 'A001'
    // Rawcode of 'Armor Crush' ability
    
    private constant integer ability_ACBid = 'A002'
    // Rawcode of 'Armor Crush (Buff)' ability
    
    private constant integer ability_ACdid = 'A000'
    // Rawcode of 'Armor Crushed' ability
    
    private constant integer buff_ACid = 'B001'
    // Rawcode of 'Armor Crush' buff
    
    private constant integer buff_ACdid = 'B000'
    // Rawcode of 'Armor Crushed' buff
    
    private constant integer dummyBuffer = 'n001'
    // Rawcode of 'DummyBuffer' unit
    
    private constant integer dummyCaster = 'n000'
    // Rawcode of 'DummyCaster' unit
    
    private constant integer crushMin = 1
    // Minimum for crush chance
    
    private constant integer crushMax = 100
    // Maximum for crush chance
    
    private constant integer crushChance = 15
    // Chance to cast Armor Crush
    
    private constant integer crushStack = 3
    // How many times Armor Crush stacks
    
    private sound crushSound = gg_snd_Feedback
    // Sound played by Armor Crush (NOTE: You must import the sound via Sound Editor)
    
    private constant integer crushSoundVolume = 100
    // Volume of the played sound
    
    private constant string crushSFX = "Abilities\\Spells\\Items\\ResourceItems\\ResourceEffectTarget.mdl"
    // Path for Armor Crush SFX
    
    private constant string crushAttach = "overhead"
    // Attachment point of Armor Crush SFX
    
    private constant attacktype attackType = ATTACK_TYPE_HERO
    // Attack type Armor Crush deals
    
    private constant damagetype damageType = DAMAGE_TYPE_FIRE
    // Damage type Armor Crush deals
    
    private constant real crushReturn = 0.02
    // Percentage of health Armor Crush returns (NOTE: This value is for level 1)
    // Each 0.01 is equal to 1% (So 0.05 would be 5%, 0.25 would be 25%, and so on)
    
    private constant real tOffset = 0
    // Floating text offset
    
    private constant real tSize = 10
    // Floating text font size
    
    private constant real tRed = 0
    // Floating text red color amount (0-100)
    
    private constant real tGreen = 0
    // Floating text green color amount (0-100)
    
    private constant real tBlue = 100
    // Floating text blue color amount (0-100)
    
    private constant real tTrans = 0
    // Floating text transparency (0-100)
    
    private constant real tLife = 3
    // Floating text life
    
    private constant real tAge = 2
    // Floating text age
    
    private constant real tVelocity = 75
    // Floating text velocity
    
    private constant real tDegrees = 90
    // Floating text degrees
    
    private constant string buffCommand = "innerfire"
    // 'Order String Use/Turn On' for 'Armor Crush (Buff)' ability
    
    // Don't change the following constant
    private constant group crushedGroup = CreateGroup() // Don't change this!
    // Don't change the above constant
endglobals

// +---------------------------------------+
// |       -=-=- END OF MODIFY -=-=-       |
// |       -=-=- END OF MODIFY -=-=-       |
// |       -=-=- END OF MODIFY -=-=-       |
// +---------------------------------------+

// +----------------------------------------------+
// |       -=-=- NO TOUCHIE PAST HERE -=-=-       |
// |       -=-=- NO TOUCHIE PAST HERE -=-=-       |
// |       -=-=- NO TOUCHIE PAST HERE -=-=-       |
// +----------------------------------------------+

private function CGSConditions takes nothing returns boolean
    return GetLearnedSkill() == ability_ACid
endfunction

private function CGSActions takes nothing returns nothing
    local unit lu = GetLearningUnit()
    local real x = GetUnitX(lu)
    local real y = GetUnitY(lu)
    local unit lc = CreateUnit(GetOwningPlayer(lu), dummyBuffer, x, y, GetUnitFacing(lu))
    call SetUnitAbilityLevel(lc, ability_ACBid, GetUnitAbilityLevel(lu, ability_ACid))
    call IssueTargetOrder(lc, buffCommand, lu)    
    call UnitApplyTimedLife(lc, 'BTLF', 1.00)
    set lu = null
    set lc = null
endfunction

private function ACConditions takes nothing returns boolean
    return GetRandomInt(crushMin, crushMax) <= crushChance and GetUnitAbilityLevel(GetTriggerUnit(), buff_ACid) > 0
endfunction

private function ACActions takes nothing returns nothing
    local unit ar = GetAttacker()
    local real x = GetUnitX(ar)
    local real y = GetUnitY(ar)
    local unit ad = GetTriggerUnit()
    local integer array damageAttacker
    local texttag actt  = CreateTextTag()
    local unit u
    call AddSpecialEffectTarget(crushSFX, ar, crushAttach)
    call DestroyEffect(bj_lastCreatedEffect)
    call PlaySoundOnUnitBJ(crushSound, crushSoundVolume, ar)
    set damageAttacker[0] = R2I(GetUnitState(ar, UNIT_STATE_LIFE))    
    call UnitDamageTarget(ad, ar, (GetUnitState(ad, UNIT_STATE_LIFE) * (crushReturn * I2R(GetUnitAbilityLevel(ad, ability_ACid)))), true, true, attackType, damageType, WEAPON_TYPE_WHOKNOWS)
    set damageAttacker[1] = R2I(GetUnitState(ar, UNIT_STATE_LIFE))
    set damageAttacker[2] = (damageAttacker[0] - damageAttacker[1])
    call CreateTextTagUnitBJ((I2S(damageAttacker[2]) + "!" ), ar, tOffset, tSize, tRed, tGreen, tBlue, tTrans)
    set actt = GetLastCreatedTextTag()
    call SetTextTagPermanentBJ(actt, false)
    call SetTextTagLifespanBJ(actt, tLife)
    call SetTextTagFadepointBJ(actt, tAge)
    call SetTextTagVelocityBJ(actt, tVelocity, tDegrees)
    if GetUnitUserData(ar) < crushStack then
        call SetUnitUserData(ar, (GetUnitUserData(ar) + 1))
        set u = CreateUnit(GetOwningPlayer(ad), dummyCaster, x, y, GetUnitFacing(ar))
        call SetUnitAbilityLevel(u, ability_ACdid, (GetUnitUserData(ar) * GetUnitAbilityLevel(ad, buff_ACid)))
        call IssueTargetOrder(u, buffCommand, ar)
        call UnitApplyTimedLife(u, 'BTLF', 2.00)
        if (not(IsUnitInGroup(ar, crushedGroup))) then
            call GroupAddUnit(crushedGroup, ar)
        endif
    endif
    set ar = null
    set ad = null
    set u = null
endfunction

private function CGRConditions takes nothing returns boolean
    return FirstOfGroup(crushedGroup) != null
endfunction

private function CGRActions takes nothing returns nothing
    local unit u
    if GetUnitAbilityLevel(GetTriggerUnit(), buff_ACdid) > 0 then
        loop
            set u = FirstOfGroup(crushedGroup)
            exitwhen u == null
            call GroupRemoveUnit(crushedGroup, u)
            call SetUnitUserData(u, 0)
        endloop
    endif
    set u = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trigCGS = CreateTrigger()
    local trigger trigAC = CreateTrigger()
    local trigger trigCGR = CreateTrigger()
    
    call TriggerRegisterAnyUnitEventBJ(trigCGS, EVENT_PLAYER_HERO_SKILL)
    call TriggerAddCondition(trigCGS, Condition(function CGSConditions))
    call TriggerAddAction(trigCGS, function CGSActions)
    
    call TriggerRegisterAnyUnitEventBJ(trigAC, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(trigAC, Condition(function ACConditions))
    call TriggerAddAction(trigAC, function ACActions)
    
    call TriggerRegisterTimerEventPeriodic(trigCGR, 1.50)
    call TriggerAddCondition(trigCGR, Condition(function CGRConditions))
    call TriggerAddAction(trigCGR, function CGRActions)
endfunction

endscope

The spell still doesn't make the sound though.
 

Naga'sShadow

Ultra Cool Member
Reaction score
49
I've had this problem before too. It will work but the editor won't let you preemptively name a variable from the the sound editor, or variable editor for that matter. I was having the problem of declaring sound variables and then not being allowed to create the sound in the sound editor. Try this, disable the trigger, create the sound then re-enable the trigger. Now the game sees the sound placed above your global deceleration line and has no issues with it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top