firefly2442 Posted October 16, 2015 Posted October 16, 2015 I have the following debug function that doesn't seem to be working: local function debug_destroyC130() local c130 = Group.getByName('C-130') for g in pairs(c130) do if g:isActive() == false then g:activate() end --there's no setLife() method ... :/ --I don't think destroy() does what we want trigger.action.explosion(g:getPosition().p, 100) end end And here's the error message: attempt to call method 'isActive' (a nil value)Am I not iterating through the group properly?
Grimes Posted October 16, 2015 Posted October 16, 2015 isActive is available to the unit class, not group. This always trips me up. And no you aren't iterating the group correctly. for i, u in pairs (c130:getUnits()) do i is the index and u is the unit object. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
scrapple Posted June 26, 2017 Posted June 26, 2017 Since we don't have a Group.isActive() function in LUA, what would be a good way of determining whether a group has been activated? I was looking at maybe getting one of the units in the group, and checking whether the unit is active using Unit.isActive(). If so, that would imply the group is active. I just wanted to see if there might be a more straightforward (easier) way. Thanks!
Chump Posted June 26, 2017 Posted June 26, 2017 (edited) If there is at least one unit in the group that is returned from Group.getUnits(), the group can be considered alive/active.local group = Group.getByName("someGroupName") if group and #group:getUnits() > 0 then -- group is alive/active endI have not tried this particular scenario to test for isActive, but I would think that non-active units would not be returned, nor even the group. I hope that I am not mistaken. I am unable to test this right now. Edited June 26, 2017 by Chump
Recommended Posts