vuongkkk
New Member
- Reaction score
- 1
My question is very simple:
Normal, everybody always use group to iterate a number of units.
However, i use the iterator is a integer array contain a instance of struct, (of cause i can control my iterator, and it worked). Like group, i do NOT loop all members in array , only units are member of my array.
I dont know which faster? Group or my iterrator
And this is my iterator
Normal, everybody always use group to iterate a number of units.
However, i use the iterator is a integer array contain a instance of struct, (of cause i can control my iterator, and it worked). Like group, i do NOT loop all members in array , only units are member of my array.
I dont know which faster? Group or my iterrator
And this is my iterator
JASS:
globals
private constant integer MAX_INSTANCE = 8190
private integer array MyGroup[MAX_INSTANCE]
private integer MyGroupCount = 0
endglobals
struct UnitData
unit u
integer index
static method create takes unit u returns UnitData
set this.u = whichU
set MyGroup[MyGroupCount] = integer(this)
set MyGroupCount = MyGroupCount + 1
set this.index = MyGroupCount
endmethod
method onDestroy takes nothing returns nothing
set MyGroupCount = MyGroupCount - 1
set UnitData(MyGroup[MyGroupCount]).index = this.index
set MyGroup[this.index-1] = MyGroup[MyGroupCount]
set MyGroup[MyGroupCount] = 0
endmethod
endstruct
function MyGroupAddUnit takes unit whichU returns UnitData
local UnitData d = UnitData.create(whichU)
return d
endfunction
function MyGroupIterator takes nothing returns nothing
local integer i = 0
local UnitData data
loop
exitwhen MyGroup<i> == 0
set data = UnitData(MyGroup<i>)
// do something with enum unit here like that
call SetUnitState(data.u, UNIT_STATE_LIFE, 10000)
call data.destroy()
endif
set i = i +1
endloop
endfunction
</i></i>