- Joined
- Oct 23, 2011
- Messages
- 182
I've been thinking
"If I have hundreds of triggers checking itemid of the used item for EVENT_PLAYER_UNIT_USE_ITEM, it would call GetManipulatedItem() hundreds of times everytime an item is used" am I right?
I decided to write this short code so I can reduce the amount I call GetManipulatedItem() or GetTriggerUnit()
The question is.. is this useful at all? (or does it even make sense)?
I think I'm doing something completely stupid and this code is pointless
If this does serve some use, would it be better for me to just create a single trigger for each itemid, save it on a hashtable with the itemid as the childkey and execute whichever trigger that is saved to the childkey of itemid each time an item is used?
"If I have hundreds of triggers checking itemid of the used item for EVENT_PLAYER_UNIT_USE_ITEM, it would call GetManipulatedItem() hundreds of times everytime an item is used" am I right?
I decided to write this short code so I can reduce the amount I call GetManipulatedItem() or GetTriggerUnit()
JASS:
library ItemUse uses Event, RegisterPlayerUnitEvent
globals
private Event USE
private unit u
private item i
endglobals
private function onUse takes nothing returns nothing
set u=GetTriggerUnit()
set i=GetManipulatedItem()
call FireEvent(USE)
endfunction
function RegisterItemUseEvent takes boolexpr c returns nothing
call RegisterEvent(c,USE)
endfunction
function GetUsingUnit takes nothing returns unit
return u
endfunction
function GetUsedItem takes nothing returns item
return i
endfunction
private module M
private static method onInit takes nothing returns nothing
set USE=CreateEvent()
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_USE_ITEM, function onUse)
endmethod
endmodule
private struct S extends array
implement M
endstruct
endlibrary
The question is.. is this useful at all? (or does it even make sense)?
I think I'm doing something completely stupid and this code is pointless
If this does serve some use, would it be better for me to just create a single trigger for each itemid, save it on a hashtable with the itemid as the childkey and execute whichever trigger that is saved to the childkey of itemid each time an item is used?