Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

changing loadout and ready time with "if ~= nil"

 
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 >> changing loadout and ready time with "if ~= nil" Page: [1]
Login
Message << Older Topic   Newer Topic >>
changing loadout and ready time with "if ~= nil" - 12/10/2018 5:51:17 AM   
orca

 

Posts: 501
Joined: 11/6/2013
Status: offline
I use this command to change the loadout and time to ready:

local unit = ScenEdit_GetUnit({name='Su-34 (Bodo) #9'})
ScenEdit_SetLoadout({UnitName = unit.name, LoadoutID = 23085, TimeToReady_Minutes = 58})

But I think this causes an error if the aircraft is not found.


I use the following to assign a unit to a mission with the "if ~= nil" coding so no error occurs if the unit isn't found.

if ScenEdit_GetUnit({Side='Russia', Name="Su-34 (Bodo) #9"}) ~= nil then
ScenEdit_AssignUnitToMission("Su-34 (Bodo) #9", "Norway strike)")
end

Is there a better way to change the loadout and time to ready for a unit to make sure there is no error if the unit is not found similar to the latter LUA example with something like the "if ~= nil" part of the code?

thanks

< Message edited by orca -- 12/10/2018 5:55:26 AM >
Post #: 1
RE: changing loadout and ready time with "if ~= ni... - 2/16/2022 9:58:57 PM   
Kennetho


Posts: 39
Joined: 3/24/2018
From: Denmark
Status: offline
Did you ever figure this out?
I’m interested in learning the same.

Changing mission and loadout.

(in reply to orca)
Post #: 2
RE: changing loadout and ready time with "if ~= ni... - 2/17/2022 7:10:18 AM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline
retbool,retval = pcall(ScenEdit_SetLoadout{UnitName = unit.name, LoadoutID = 23085, TimeToReady_Minutes = 58}) ;
if retbool and retval then
-- success
end

retbool will be true or false, if true ScenEdit_SetLoadout didn't fail and retval will hold whatever value was returned (a boolean itself), if it's false then it failed, and retval is either nil or contains the error message.


(in reply to Kennetho)
Post #: 3
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> changing loadout and ready time with "if ~= nil" 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.000