- Joined
- Jan 11, 2009
- Messages
- 3,414
I know i've posted this before, but it's not solved yet, and i really want it to work.
I'm making a little grouping system for my map, and i have a function that checks for a unit of specific type inside a group, and, if successful, returns it.
It works perfectly the first time, but it will only run once per group.
Here's the script:
I know it leaks a unit handle, but i really don't know how to fix that sin'ce it's the return.
But what's wrong whith this script?
I'd be thankful for answers.
EDIT: I forgot to say, the gruop is an array indexed by it's members custom value. So if input unit is in group 3, the function will look for units of that type in group 3 in the array.
I'm making a little grouping system for my map, and i have a function that checks for a unit of specific type inside a group, and, if successful, returns it.
It works perfectly the first time, but it will only run once per group.
Here's the script:
JASS:
function getFreeUnit takes unit u returns unit
local unit temp = null
local group g = CreateGroup()
if GetUnitUserData(u)!=0 then
set g = udg_sq_g[GetUnitUserData(u)]
loop
exitwhen GetUnitTypeId(temp) == 'h002'
set temp = FirstOfGroup(g)
if GetUnitTypeId(temp) != 'h002' then
call GroupRemoveUnit(g, temp)
else
return temp
endif
endloop
endif
call DestroyGroup(g)
set g = null
return temp
endfunction
I know it leaks a unit handle, but i really don't know how to fix that sin'ce it's the return.
But what's wrong whith this script?
I'd be thankful for answers.
EDIT: I forgot to say, the gruop is an array indexed by it's members custom value. So if input unit is in group 3, the function will look for units of that type in group 3 in the array.
Last edited: