- Joined
- Feb 27, 2007
- Messages
- 5,578
I've got to check the spell being cast is in a list of spells (spells can't be removed from the list once added) and if so do yadda yadda. Since this search will run every time any spell is cast I want the check to be as lightweight as possible. Which is the better option? (or neither?)
or
JASS:
struct Abils extends array
integer a
static integer NUM_SPELLS //set elsewhere
static method Find takes integer aid returns thistype
local integer i = 0
loop
exitwhen i >= NUM_SPELLS
if Abils[i].a == aid then
return Abils[i]
endif
set i = i+1
loop
endmethod
endstruct
function OnSpell takes nothing returns nothing
local Abils a = Abils.Find(GetSpellAbilityId())
if a.a != 0 then
call Whatever()
endif
endfunction
JASS:
globals
constant integer Spell_List
hashtable ht = InitHashTable()
//When spell is added to list the appropraite hashtable entry is created
ednglobals
function OnSpell takes nothing returns nothing
if ht.LoadBoolean(ht, Spell_List, GetSpellAbilityId() then
call Whatever()
endif
endfunction