- Joined
- Sep 19, 2006
- Messages
- 152
I'm compressing my previously-very-long item-acquired trigger into a more efficient item/function array trigger, thanks to some of the feedback I've received. In my map, some items (when acquired) affect no variables, others 1, some 2, a few 3, and fewer, more than 3. Many of these affected variables are not exclusive to a particular item, meaning that some items (when acquired) will affect value_x, some value_y, some value_z, some value_x and value_y, some value_x and value_z, etc. Is the following trigger an efficient method for putting this concept into effect?
(Please ignore the missing EFFECT in the InitTrig_AcquiresAnItem function.)
(Please ignore the missing EFFECT in the InitTrig_AcquiresAnItem function.)
JASS:
function AcquiresAnItem_Action01 takes nothing returns nothing
local item trig_item = GetManipulatedItem ()
local unit trig_unit
local trigger trig_itemA
local integer trig_itemJ = GetItemTypeId (trig_item)
local integer trig_itemP = LoadInteger (udg_ItemHash, trig_itemJ, 1) // Number of variables influenced by "trig_item"
local integer trig_unitQ
local integer trig_itemV
local integer loopV
if trig_itemP > 0 then
set trig_itemP = trig_itemP + 1
set trig_unit = GetManipulatingUnit ()
set udg_ItemUnit = trig_unit
set trig_unitQ = GetPlayerId (GetOwningPlayer (trig_unit))
set udg_PlayerNumber = trig_unitQ
set trig_itemA = LoadTriggerHandle (udg_ItemHash, trig_itemJ, 0)
set loopV = 2
loop
exitwhen loopV > trig_itemP
set trig_itemV = LoadInteger (udg_ItemHash, trig_itemJ, loopV)
set udg_ItemValue = trig_itemV
call TriggerEvaluate (trig_itemA)
set loopV = loopV + 1
endloop
set trig_itemA = null
set trig_unit = null
endif
set trig_item = null
endfunction
function InitTrig_AcquiresAnItem takes nothing returns nothing
set gg_trg_AcquiresAnItem = CreateTrigger ()
call DisableTrigger (gg_trg_AcquiresAnItem)
call TriggerAddAction (gg_trg_AcquiresAnItem, function AcquiresAnItem_Action01)
endfunction
Last edited: