changing loadout and ready time with "if ~= nil" (Full Version)

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



Message


orca -> changing loadout and ready time with "if ~= nil" (12/10/2018 5:51:17 AM)

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




Kennetho -> RE: changing loadout and ready time with "if ~= nil" (2/16/2022 9:58:57 PM)

Did you ever figure this out?
I’m interested in learning the same.

Changing mission and loadout.




KnightHawk75 -> RE: changing loadout and ready time with "if ~= nil" (2/17/2022 7:10:18 AM)

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.





Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
5.296875