- Joined
- Sep 19, 2006
- Messages
- 152
I have a really long trigger that basically reads if you acquire item of type X, do Y. However, there are like 200 items and it seems that some sort of function array would be more practical, if I could make it work. Can someone steer me in the right direction?
Old System
"Newish" system (before the trig_itemJ's and f's are assigned as arrays:
My ultimate goal is to set (at Initialization) a set of arrays like the following:
set FunctionArray1 ['hbth'] = "GoldProtection"
set IntegerArray2 ['hbth'] = 1
function GoldProtection takes integer trig_unitQ, integer V returns nothing
set udg_PlayerGoldProt [trig_unitQ] = udg_PlayerGoldProt [trig_unitQ] + V
endfunction
function AcquiresAnItem_Action01 takes nothing returns nothing
local item trig_item = GetManipulatedItem ()
local integer trig_itemJ = GetItemTypeId (trig_item)
local unit trig_unit = GetManipulatingUnit ()
local integer trig_unitQ = GetPlayerId (GetOwningPlayer (trig_unit))
call Array1 [trig_itemJ] (trig_unitQ, Array2 [trig_itemJ])
set trig_unit = null
set trig_item = null
endfunction
[/code]
Old System
JASS:
function AcquiresAnItem_Action01 takes nothing returns nothing
local item trig_item = GetManipulatedItem ()
local integer trig_itemJ = GetItemTypeId (trig_item)
local unit trig_unit = GetManipulatingUnit ()
local integer trig_unitQ = GetPlayerId (GetOwningPlayer (trig_unit))
// Tarba's Hood
if trig_itemJ == 'hbth' then
set udg_PlayerGoldProt [trig_unitQ] = udg_PlayerGoldProt [trig_unitQ] + 1
set trig_unit = null
set trig_item = null
return
endif
endfunction
"Newish" system (before the trig_itemJ's and f's are assigned as arrays:
JASS:
function GoldProtection takes integer trig_unitQ, integer V returns nothing
set udg_PlayerGoldProt [trig_unitQ] = udg_PlayerGoldProt [trig_unitQ] + V
endfunction
function AcquiresAnItem_Action01 takes nothing returns nothing
local item trig_item = GetManipulatedItem ()
local integer trig_itemJ = GetItemTypeId (trig_item)
local unit trig_unit = GetManipulatingUnit ()
local integer trig_unitQ = GetPlayerId (GetOwningPlayer (trig_unit))
local string f
// Tarba's Hood
if trig_itemJ == 'hbth' then
set f = "GoldProtection"
call f (trig_unitQ, 1)
set trig_unit = null
set trig_item = null
set f = null
return
endif
endfunction
My ultimate goal is to set (at Initialization) a set of arrays like the following:
set FunctionArray1 ['hbth'] = "GoldProtection"
set IntegerArray2 ['hbth'] = 1
function GoldProtection takes integer trig_unitQ, integer V returns nothing
set udg_PlayerGoldProt [trig_unitQ] = udg_PlayerGoldProt [trig_unitQ] + V
endfunction
function AcquiresAnItem_Action01 takes nothing returns nothing
local item trig_item = GetManipulatedItem ()
local integer trig_itemJ = GetItemTypeId (trig_item)
local unit trig_unit = GetManipulatingUnit ()
local integer trig_unitQ = GetPlayerId (GetOwningPlayer (trig_unit))
call Array1 [trig_itemJ] (trig_unitQ, Array2 [trig_itemJ])
set trig_unit = null
set trig_item = null
endfunction
[/code]