'Nil' Functions, Error Handling, and Destroyed Units (Full Version)

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



Message


gpotter511 -> 'Nil' Functions, Error Handling, and Destroyed Units (7/22/2018 8:33:41 PM)

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!




tjhkkr -> RE: 'Nil' Functions, Error Handling, and Destroyed Units (7/24/2018 1:59:57 PM)

Hey there, can you cut and paste the error you are receiving?




michaelm75au -> RE: 'Nil' Functions, Error Handling, and Destroyed Units (7/26/2018 11:11:07 AM)

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




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
1.875