struct ItemCustomValue
integer cv1 = 0 //may as well assign a default value
//type name [= value]
//etc
endstruct
//to apply it to an item
call SetItemUserData(someItem,ItemCustomValue.create())
//to use it
local ItemCustomValue dat = GetItemUserData(someItem)
//use dat.cv1 and any other values. For example:
call BJDebugMsg("The value of dat.cv1 is: " + I2S(dat.cv1))
//to destroy it, when you're done with the item to prevent an index leak
call dat.destroy()
give every unit a custom value when they enter the map (so first units value will be 1, second's 2 etc). then make real variables Value1 and Value2 etc (huge arrays). then set them to the unit's values like this:
set Value2[custom value of [unit]] to [whatever value u want]
Needs a good indexing algorithm, which is possible but already implemented in structs (and such it is much easier to just use them).give every unit a custom value when they enter the map (so first units value will be 1, second's 2 etc). then make real variables Value1 and Value2 etc (huge arrays). then set them to the unit's values like this:
set Value2[custom value of [unit]] to [whatever value u want]
Needs a good indexing algorithm, which is possible but already implemented in structs (and such it is much easier to just use them).
To index units by custom value, you need a good algorithm (efficient, thorough, relatively low-cost, and accurate), and seeing as the struct example I provided has such an algorithm built into it (in vJass) there really isn't any reason to do it another way if you have vJass available (which everyone should).i didnt understand a word of that oO
Of course your way works, with an indexing algorithm. That's what I've said all along.
local STRUCTNAME variablename = STRUCTNAME.allocate()
)library UserData initializer InitTrig
globals
private hashtable table
endglobals
struct userdata
method store takes unit u, integer data returns nothing
call SaveInteger(table, GetHandleId(u), this, data)
endmethod
method get takes unit u returns integer
return LoadInteger(table, GetHandleId(u), this)
endmethod
endstruct
private function InitTrig takes nothing returns nothing
set table = InitHashtable()
endfunction
endlibrary
private function test takes nothing returns nothing
local userdata u = userdata.create()
local unit x = CreateUnit(Player(0), 'hfoo', 0, 0, 0)
call u.sett(x, 50)
call BJDebugMsg(I2S(u.get(x)))
endfunction
private function test takes nothing returns nothing
local userdata u = userdata.create()
local unit x = CreateUnit(Player(0), 'hfoo', 0, 0, 0)
call u.store(x, 50)
call BJDebugMsg(I2S(u.get(x)))
endfunction