'Nil' Functions, Error Handling, and Destroyed Units

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
gpotter511
Posts: 52
Joined: Wed Oct 04, 2017 12:55 pm

'Nil' Functions, Error Handling, and Destroyed Units

Post by gpotter511 »

EDIT: On further review, I think I may have resolved this by appending "Tool_EmulateNoConsole(true)".

If I'm interpreting this correctly, the function is failing because I'm using the console. But, if I were to utilize the below script in an Action, the "~=nil" language would ensure the script successfully completes. Can folks confirm? Thank you!

ORIGINAL MESSAGE:

All -

I've been playing around with the use of "if, then" phrases and nil functions this weekend. My ultimate objective is to move aircraft to an OPFOR base once that base has been "captured". I'm successfully able to accomplish this for units known to exist.

Trouble arises when I attempt to ensure a series of such moves will occur even if one indicated unit is destroyed. If I am moving Eagle #1-#3, and Eagle #2 has been destroyed, then the script fails.

My script is virtually identical to this example pulled from CMANO Chains of War's "Okinawa Bound" mission:

if ScenEdit_GetUnit({Side='Japan-United States', Name='Strike Group 1'}) ~= nil then
ScenEdit_AssignUnitToMission('Strike Group 1', 'Strike Group 1 Task 3')
end
if ScenEdit_GetUnit({Side='Japan-United States', Name='Strike Group 2'}) ~= nil then
ScenEdit_AssignUnitToMission('Strike Group 2', 'Strike Group 2 Task 2')
end
if ScenEdit_GetUnit({Side='Japan-United States', Name='JDS Soryu'}) ~= nil then
ScenEdit_AssignUnitToMission('JDS Soryu','Okinawa Phib Zone')
end
if ScenEdit_GetUnit({Side='Japan-United States', Name='JDS Takashio'}) ~= nil then
ScenEdit_AssignUnitToMission('JDS Takashio','Okinawa Phib Zone')
end


I would think the purpose of the "~= nil" portion of this function is that, if a given unit - say, Strike Group 2 - has been destroyed, CMANO will recognize that unit is "nil", disregard that statement, and move on to subsequent functions. But despite the "~= nil" language, an error message is served and the remainder of the script is not executed.

Can anyone describe the appropriate modifications to ensure that, if a unit is "nil", CMANO will continue on and perform the remainder of the script?

Thanks!
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: 'Nil' Functions, Error Handling, and Destroyed Units

Post by tjhkkr »

Hey there, can you cut and paste the error you are receiving?
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
User avatar
michaelm75au
Posts: 12467
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: 'Nil' Functions, Error Handling, and Destroyed Units

Post by michaelm75au »

Yes, I created the Tool_EmulateNoConsole(true) function to allow you run event type scripts in the Console to check if they run okay.
Michael
Post Reply

Return to “Lua Legion”