- Joined
- Jan 30, 2020
- Messages
- 758
In JASS, what is the best way of getting a unit from a group by index?
Is it even possible without shuffleing units to a temp-group and back to the original group again (like the following)?
It is possible to have a copy of the group as an array I guess...
Is it even possible without shuffleing units to a temp-group and back to the original group again (like the following)?
JASS:
function groupGetUnitByIndex takes group g, integer index returns unit
local integer i = 0
local group tempGroup = CreateGroup()
local unit u
local unit returnUnit = null
loop
set u = FirstOfGroup(g)
exitwhen u == null
if i == index then
set returnUnit = u
endif
set i = i + 1
call GroupRemoveUnit(g,u)
call GroupAddUnit(tempGroup, u)
endloop
loop
set u = FirstOfGroup(tempGroup)
exitwhen u == null
call GroupRemoveUnit(tempGroup,u)
call GroupAddUnit(g, u)
endloop
call DestroyGroup(tempGroup)
set tempGroup = null
return returnUnit
endfunction
It is possible to have a copy of the group as an array I guess...