Proxy404 Posted January 8, 2021 Posted January 8, 2021 (edited) 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? Edited January 8, 2021 by Proxy404
Habu_69 Posted January 8, 2021 Posted January 8, 2021 The log error in line 14 means DCS can not identify the object bravo. Usually means the object does not exist. Perhaps some issue with ME group name, case, etc. Or . . Is it late activated? Spawned?
reptile92 Posted January 8, 2021 Posted January 8, 2021 For debug, do the group:findbyname in the scheduler function. Just to test if the issue is global function or the fact the group cannot be instance (my opinion sound like Habu one, issue on this group. However, late activated is not an. issue for a find)
Proxy404 Posted January 8, 2021 Author Posted January 8, 2021 1 hour ago, Habu_69 said: The log error in line 14 means DCS can not identify the object bravo. Usually means the object does not exist. Perhaps some issue with ME group name, case, etc. Or . . Is it late activated? Spawned? Like I mentioned above, if I move the declaration into the function, it works fine, so unlikely an issue with the ME name. But I think you solved my issue with the point on the spawn time. Bravo-1 is a player group. By that I mean the humans are picking the planes in Bravo-1 and Bravo-1 would be non-existent until the human(s) hit "fly". So there is a timing issue with when the bravo variable is declared. I'd need to update bravo when a plane spawns in and change the "if bravo:IsActive() then" condition to just "if bravo then". Thanks @Habu_69!
reptile92 Posted January 8, 2021 Posted January 8, 2021 you can also look at set_client. depend what you need. a set with filterstart is automatically update when a new object meet the filter requirement
Recommended Posts