Page 1 of 1

'Nil' Functions, Error Handling, and Destroyed Units

Posted: Sun Jul 22, 2018 5:33 pm
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!

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

Posted: Tue Jul 24, 2018 10:59 am
by tjhkkr
Hey there, can you cut and paste the error you are receiving?

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

Posted: Thu Jul 26, 2018 8:11 am
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.