I recently tried moving on from GUI to vJASS, and learned that scopes are quite useful for making convenient private globals;
not "global unit spell_A_Caster", etc but just "private global unit c" within "scope spell_A".
And then I found out that "TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)" is very inefficient cuz it fires event for every player.
So I tried to change it to "TriggerRegisterUnitEvent(t,u,EVENT_UNIT_SPELL_EFFECT)" and call the registering function when a Hero is selected. (AOS style map)
Then I realized that I have intializers for current spells' scopes. Initializers require InitTrig, and InitTrig is not compatiable with TriggerRegisterUnitEvent.
So I just removed initializer and scope worked well.
Then what does a initializer do? Is it safe to remove it?
Below are the spell trigger examples, one with initializer and one without, both are performing well (at least in my perspective).
not "global unit spell_A_Caster", etc but just "private global unit c" within "scope spell_A".
And then I found out that "TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)" is very inefficient cuz it fires event for every player.
So I tried to change it to "TriggerRegisterUnitEvent(t,u,EVENT_UNIT_SPELL_EFFECT)" and call the registering function when a Hero is selected. (AOS style map)
Then I realized that I have intializers for current spells' scopes. Initializers require InitTrig, and InitTrig is not compatiable with TriggerRegisterUnitEvent.
So I just removed initializer and scope worked well.
Then what does a initializer do? Is it safe to remove it?
Below are the spell trigger examples, one with initializer and one without, both are performing well (at least in my perspective).
JASS:
scope spell_A initializer InitTrig_spell_A
globals
private unit u
endglobals
private function spell_A_Conditions takes nothing returns boolean
if ((GetSpellAbilityId() == 'A001')) then
set u = GetTriggerUnit()
endif
return false
endfunction
private function InitTrig_spell_A takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition( function spell_A_Conditions ) )
set t = null
endfunction
endscope
JASS:
scope spell_A
globals
private unit u
endglobals
private function spell_A_Conditions takes nothing returns boolean
if GetSpellAbilityId() == 'A001' then
set u = GetTriggerUnit()
endif
return false
endfunction
function spell_A_register takes unit u returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterUnitEvent(t,u,EVENT_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition( function spell_A_Conditions ) )
set t = null
endfunction
endscope
// call spell_A_register(u) is called when the hero using this spell is selected.