Trying to reference a global variable in a scheduler object and getting the error:
Error in timer function: [string "..."]:14: attempt to index global 'bravo' (a nil value)
Here is the script I'm trying to run. It is a loop that looks for a group to pass into a zone_polygon. Once it detects that all or part of the group is in the zone, it checks each unit's altitude to see if they fly over 1500 ft. If any of them do, it spits out a message and stops the scheduler.
BASE:TraceAll( false )
BASE:TraceClass("SCHEDULER")
BASE:TraceClass("TIMER")
bravo = GROUP:FindByName('Bravo-1')
groupPolygon = GROUP:FindByName("NoFlyZone")
tzLimit = ZONE_POLYGON:New("NoFlyZone",groupPolygon)
checkOverHeight = SCHEDULER:New(nil,
function()
BASE:E('looking for bravo')
if bravo:IsActive() then
BASE:E('found bravo')
if bravo:IsPartlyOrCompletelyInZone(tzLimit) then
BASE:E('bravo in zone')
local units = bravo:GetUnits()
for x=1, #units do
BASE:E('check bravo height')
if bravo:GetUnit(x):GetAltitude() > 457.2 then
BASE:E('bravo height exceeded')
bravo:MessageToAll("Bravo height: " .. bravo:GetUnit(x):GetAltitude(), 30)
checkOverHeight:Stop()
end
end
end
end
end, {}, 0, 2)
I have a similar script working where the bravo, GroupPolygon, and tzLimit are declared as locals inside the scheduler function. However, I feel like I should be able to reference the global declarations and save some logic ticks on not instantiating the groups and zone every 2 seconds. Anyone know of a way to do this?