- Joined
- Aug 7, 2013
- Messages
- 1,338
Hi,
Suppose I've got the following code.
So I need to iterate over all units of a certain type, and then do something to each one from a struct instance.
I wanted to do
While I am certain my functions will work, I want to know if it is possible for a handle id to have the same value as a unitID--if so, then my method of using Table is not safe.
In addition, suppose the following happens (reference the above code for what the functions do).
Will my code be ok? That is, each player will see every footman tinted differently.
Suppose I've got the following code.
JASS:
local integer pid
static method create takes integer pid returns nothing
...
set this.pid = pid
return this
endmethod
method foo takes unit u returns nothing
if GetLocalPlayer() == Player(pid) then
call SetUnitVertexColor(u, GetRandomInt(0, 255), GetRandomInt(0, 255), GetRandomInt(0, 255))
endif
endmethod
static method main takes nothing returns nothing
local unit u = GetEnumUnit()
local myStruct my = myTable[GetUnitTypeId(u)]
call my.foo(u)
endmethod
method do takes integer unitID returns nothing
local group g = CreateGroup()
set g = GetUnitsOfTypeIdAll(unitID)
set myTable[unitID] = this
call ForGroup(g, function main)
call DestroyGroup(g)
set g = null
endmethod
So I need to iterate over all units of a certain type, and then do something to each one from a struct instance.
I wanted to do
GetHandleId(g)
as the index for the struct, but apparently there is no native like GetEnumGroup()
that can be called inside a for group function. I also thought about GetLastCreatedGroup()
, but I have no idea how that would behave. While I am certain my functions will work, I want to know if it is possible for a handle id to have the same value as a unitID--if so, then my method of using Table is not safe.
In addition, suppose the following happens (reference the above code for what the functions do).
JASS:
local integer unitID = 'hfoo'
local integer i = 0
local myStruct my
loop
exitwhen i == TOTAL_PLAYERS
set my = myStruct.create(i)
call my.do(unitID)
set i = i + 1
endloop
Will my code be ok? That is, each player will see every footman tinted differently.