Missing Unit causing error (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion



Message


trupright -> Missing Unit causing error (2/8/2022 9:02:13 PM)

Hi Everyone,

So I have a function which executes random direction changes for a variety of units. It's set to occur every 15 minutes. The problem I'm having is that as units are destroyed (as they tend to do in these games), the script errors out if a unit no longer exists.

So I know this is probably a simple one-line item I need in the function to ask whether the ship exists.

I'm still a relative newbie to thi. I call the groups, and then cycle through the units in the group, tasking them to change direction (group stays together). However, if a ship is missing, the script errors out.


Any assistance would be welcome.

Thanks!




stilesw -> RE: Missing Unit causing error (2/8/2022 9:24:51 PM)

Tim,

You can check to see if the unit exists first.

u = ScenEdit_GetUnit({side=side,name=name})
if u ~= nil then
Execute your course change Lua code
end
}

Do this for each unit in question and if has been destroyed will still do what you want for the others.

-WS




trupright -> RE: Missing Unit causing error (2/9/2022 1:03:07 PM)

Thank you. 3-minute fix and all is well again. Your help is very much appreciated!

Tim




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
1.375