substance
New Member
- Reaction score
- 34
I'm not sure if this is common sense or maybe even a bad idea, but to me it seems perfect for what i need. Anyway, the idea is for every unit to have his own 'unit data' struct and making accessing the user-created information for that unit easy to access from any function. This gets rid of the need of EVER attatching data to units.
Essentially it's just creating a global struct for every unit that holds all the information that you'll need to get to throught your map's code and then tying that information to a 'Id', and then giving every unit his own Id. This is nothing new really, but doing so without having to 'attatch' the struct to a unit (using a 'Set and Get' methode ie. handle vars, CSdata) is something I havent seen.
So setting it up would be pretty simple, this function would run when a player picks his hero or a unit enters map or whatever :
Obviously classstruct would have all the variables you need throughout your map. You would retrieve a unit's info like this :
So you can see you can freely edit any variables from anywhere without having to attatch anything. Actually, you dont even have to localize the data if you dont want to :
This same idea could be applied for PlayerData, but it'd be even easier because you could use their playerid instead of making your own.
Essentially it's just creating a global struct for every unit that holds all the information that you'll need to get to throught your map's code and then tying that information to a 'Id', and then giving every unit his own Id. This is nothing new really, but doing so without having to 'attatch' the struct to a unit (using a 'Set and Get' methode ie. handle vars, CSdata) is something I havent seen.
So setting it up would be pretty simple, this function would run when a player picks his hero or a unit enters map or whatever :
JASS:
globals
integer ClassId = 0
classstruct array ClassData
endglobals
struct classstruct
boolean example
// and all the unit's needed variables would go here
endstruct
function AUnitEnters takes nothing returns nothing
set ClassData[ClassId] = classstruct.create()
call SetUnitUserData(GetTriggerUnit(),ClassId)
set ClassId = ClassId + 1
endfunction
Obviously classstruct would have all the variables you need throughout your map. You would retrieve a unit's info like this :
JASS:
function Example takes nothing returns nothing
local classstruct data = ClassData[GetUnitUserData(GetTriggerUnit())]
if data.example then
set data.example = false
endif
endfunction
So you can see you can freely edit any variables from anywhere without having to attatch anything. Actually, you dont even have to localize the data if you dont want to :
JASS:
function Example takes nothing returns nothing
if ClassData[GetUnitUserData(GetTriggerUnit())].example then
set ClassData[GetUnitUserData(GetTriggerUnit())].example = false
endif
endfunction
This same idea could be applied for PlayerData, but it'd be even easier because you could use their playerid instead of making your own.