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

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
orca
Posts: 545
Joined: Wed Nov 06, 2013 4:59 pm

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

Post by orca »

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
User avatar
Kennetho
Posts: 65
Joined: Sat Mar 24, 2018 7:23 am
Location: Denmark

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

Post by Kennetho »

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

Changing mission and loadout.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: changing loadout and ready time with

Post by KnightHawk75 »

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.
Last edited by KnightHawk75 on Tue Mar 01, 2022 10:34 am, edited 1 time in total.
Parel803
Posts: 962
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: changing loadout and ready time with

Post by Parel803 »

Nice.
Not sure what goes wrong but I change 3 units on base. Works fine changing to Maritime surveillance or reserve. But when I change it to the ASW role (IDnr) it says (Reserve[Available]). Tries it on NH-90, P-3 Orion and the P-8 Poseidon. Was wondering if someone else had the same issue or just on my side.
bset regards GJ
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: changing loadout and ready time with

Post by KnightHawk75 »

Parel803 wrote: Sun Feb 27, 2022 7:00 pm Nice.
Not sure what goes wrong but I change 3 units on base. Works fine changing to Maritime surveillance or reserve. But when I change it to the ASW role (IDnr) it says (Reserve[Available]). Tries it on NH-90, P-3 Orion and the P-8 Poseidon. Was wondering if someone else had the same issue or just on my side.
bset regards GJ
Do you have the needed munitions in the magazine, and/or have unlimited mags turned on? Because if you don't and you don't use the the IgnoreMagazine=true parameter then if munitions are missing it'll just set things to reserved.

How to tell it to ignore the magazine.

Code: Select all

-- set loadout for P-8 (db492), bypass needing munitions in the mag.
local retbool,retval = pcall(ScenEdit_SetLoadout,{UnitName = "Knighthawk #1", LoadoutID = 28501, TimeToReady_Minutes = 58, IgnoreMagazines=true}) ;
if retbool and retval then print('success'); else print('failed'); end
Parel803
Posts: 962
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: changing loadout and ready time with

Post by Parel803 »

Thx, checking
regards GJ

That was it, feeling stupid again.
Thx for you time, sorry for wasting it :-)
Post Reply

Return to “Lua Legion”