Page 1 of 1

Missing Unit causing error

Posted: Tue Feb 08, 2022 7:02 pm
by DeletedUser1781801786
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!

RE: Missing Unit causing error

Posted: Tue Feb 08, 2022 7:24 pm
by stilesw
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

RE: Missing Unit causing error

Posted: Wed Feb 09, 2022 11:03 am
by DeletedUser1781801786
Thank you. 3-minute fix and all is well again. Your help is very much appreciated!

Tim