- Joined
- Aug 9, 2015
- Messages
- 33
Hi,
I have been wondering whether in terms of optimilization it is better to have one function that checks what spell is being used and calls the appropiate function, or whether it is better to have many functions checking for which spells are being used.
In the example below, which is in lua but I believe for the sake of the question it does not matter, I present two scripts (with errors) that would be a graphical interpretation of what I'm talking about.
In the first script each spell has it's own trigger, for the function that initializes actions checks only for one spell. In the second script all spells "belong" to one trigger, as the function initialized by the trigger checks for all spells in the map, and it would call appropiate other functions.
I have been wondering whether in terms of optimilization it is better to have one function that checks what spell is being used and calls the appropiate function, or whether it is better to have many functions checking for which spells are being used.
In the example below, which is in lua but I believe for the sake of the question it does not matter, I present two scripts (with errors) that would be a graphical interpretation of what I'm talking about.
Lua:
do
function rocket_init()
if GetSpellAbilityId() == 'blah' then
blah blah blah
end
end
OnMapInit(function ()
local rocketinit = CreateTrigger()
TriggerAddAction(rocketinit, rocket_init)
TriggerRegisterAnyUnitEventBJ(rocketinit, EVENT_PLAYER_UNIT_SPELL_CAST)
end)
end
do
function spells_init()
if GetSpellAbilityId() == 'blah2' then
blah blah blah
end
if GetSpellAbilityId() == 'blah3' then
blah blah blah
end
if GetSpellAbilityId() == 'blah4' then
blah blah blah
end
OnMapInit(function ()
local spellsinit = CreateTrigger()
TriggerAddAction(spellsinit, spells_init)
TriggerRegisterAnyUnitEventBJ(spellsinit, EVENT_PLAYER_UNIT_SPELL_CAST)
end)
end
In the first script each spell has it's own trigger, for the function that initializes actions checks only for one spell. In the second script all spells "belong" to one trigger, as the function initialized by the trigger checks for all spells in the map, and it would call appropiate other functions.