• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] GetSpellAbilityId() returning 0..?

Status
Not open for further replies.

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
JASS:
scope knife initializer i
    globals
        private constant integer KNIFECODE='A004'
    endglobals
    
    private function c takes nothing returns boolean
        return GetSpellAbilityId()==KNIFECODE
    endfunction
    
    private function a takes nothing returns nothing
         call BJDebugMsg("rawr")
    endfunction
    
    private function i takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t,Condition(function c))
        call TriggerAddAction(t,function a)
    endfunction
endscope

Any reason the debug message wouldn't be displayed? The spell is based on banish.
 

Cokemonkey11

Spell Reviewer
Level 29
Joined
May 9, 2006
Messages
3,534
The initializer runs.

Check this too...:

bed0783c0d679c89c6e48922754f8de8.png
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
xxdingo93xx said:
No he shouldn't null the local trigger. Why? Because.
Umm..
Vexorian said:
First of all, always null handle local variables when they reach the end of their 'scope', always. Plenty of times, it is not necessary to null a local. But turning the nulling into a mechanical process while trivializing it is better than having to give thought to such a lame thing... Just to save a couple of lines of codee...
 
Level 2
Joined
Jul 17, 2009
Messages
27
It's a good habit to get into. Unless you know why you should be nulling or not nulling your variables, always null them at the end of their scope.

The obscure bugs people are thinking about relate to timers and dynamic triggers.
 
Tell us what happens when you do this;

JASS:
scope knife initializer i
    globals
        private constant integer KNIFECODE='A004'
    endglobals

    private function c takes nothing returns boolean
        if GetSpellAbilityId()==KNIFECODE then
            call BJDebugMsg("Spell runs")
            return false
        endif
        call BJDebugMsg(I2S(GetSpellAbilityId()) + " != " + I2S(KNIFECODE)
        return false
    endfunction

    private function i takes nothing returns nothing
        local trigger t=CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(t,Condition(function c))
    endfunction
endscope
 
Status
Not open for further replies.
Top