• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Item-Function trigger review

Status
Not open for further replies.
Level 5
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.)


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:
Level 5
Joined
Sep 19, 2006
Messages
152
One question: do hashtables have to be filled in sequence, i.e slot 0 first, then 1, then 2, etc.? (I was thinking about using slot 10 for the "item properties" value.)
 
Level 5
Joined
Sep 19, 2006
Messages
152
Hmm. Apparently each operation is a trigger that must be saved/loaded individually...

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, 0)  // Number of variables influenced by "trig_item"
    local integer trig_unitQ
    local integer trig_itemV
    local integer loopV
    local integer loadV

    if trig_itemP > 0 then
        set trig_unit = GetManipulatingUnit ()
        set udg_ItemUnit = trig_unit
        set trig_unitQ = GetPlayerId (GetOwningPlayer (trig_unit))
        set udg_PlayerNumber = trig_unitQ
        set loopV = 1
        loop
            exitwhen loopV > trig_itemP
            set loadV = loopV * 10
            set trig_itemA = LoadTriggerHandle (udg_ItemHash, trig_itemJ, loadV)
            set trig_itemV = LoadInteger (udg_ItemHash, trig_itemJ, loadV + 1)
            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 TriggerAddAction (gg_trg_AcquiresAnItem, function AcquiresAnItem_Action01)
endfunction

For the purpose of readability, I saved each trigger and value as a multiple of 10, such as 10 and 11, 20 and 21, etc.
 
Status
Not open for further replies.
Top