Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Missing Unit causing error

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Missing Unit causing error Page: [1]
Login
Message << Older Topic   Newer Topic >>
Missing Unit causing error - 2/8/2022 9:02:13 PM   
trupright

 

Posts: 9
Joined: 10/6/2021
Status: offline
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!
Post #: 1
RE: Missing Unit causing error - 2/8/2022 9:24:51 PM   
stilesw


Posts: 1497
Joined: 6/26/2014
From: Hansville, WA, USA
Status: offline
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


_____________________________

“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)

(in reply to trupright)
Post #: 2
RE: Missing Unit causing error - 2/9/2022 1:03:07 PM   
trupright

 

Posts: 9
Joined: 10/6/2021
Status: offline
Thank you. 3-minute fix and all is well again. Your help is very much appreciated!

Tim

(in reply to stilesw)
Post #: 3
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Missing Unit causing error Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

1.015