- Joined
- Nov 22, 2006
- Messages
- 1,260
Does anyone know what's wrong with this function:
I know there's no need for destroying boolexprs that are not generated with And() or Or(), so you don't have to tell me that .
The error occurs: "uninitialized variable blabla_closest in function GetClosestUnit"
JASS:
scope GetClosestUnit
globals
player P = Player(0)
unit closest
endglobals
private function GetClosestUnit_Filter takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(), P)
endfunction
function GetClosestUnit takes real x, real y returns unit
local real md = 1000000000000
local real d
local group g = CreateGroup()
local boolexpr b = Condition(function GetClosestUnit_Filter)
local unit u
local real dx
local real dy
call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, b)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
set dx = GetUnitX(u) - x
set dy = GetUnitY(u) - y
if (dx * dx + dy * dy < md) then
set closest = u
set md = dx * dx + dy * dy
endif
endloop
call DestroyGroup(g)
call DestroyBoolExpr(b)
set g = null
set b = null
return closest
endfunction
endscope
I know there's no need for destroying boolexprs that are not generated with And() or Or(), so you don't have to tell me that .
The error occurs: "uninitialized variable blabla_closest in function GetClosestUnit"
Last edited: