To emulate the expected outcome from an event, put 'Tool_EmulateNoConsole(true)' at the start of the script to be tested it is not required in the event code as the script is already not running in a console. Which requires the designer to cater for the specific error conditions. My intent is have all command errors behave in the same fashion in the console window and the command errors outside a console behave without stopping the script. Now, these event scripts will run without any in-game message showing, and the designer should check the result of the command and handle any error condition, and let the remaining script run as needed. One issue with commands running in an event is that sometimes they fail with an in-game message that actually stops the rest of the script from running. If the command runs outside the console (as in an event script), it will not fail with a visible error but return a nil or or some other value. _errmsg_) else print('Something else') endĭue to how errors are now handle from SR7, if a command fails in the console window, it will show an error. If _errnum_ ~= 0 then print('Failed to add:'. Local mission = ScenEdit_AddMission('USA','Marker strike','strike',) Without the new error handling, the script below would probably terminate after the SE_AddMission() and the rest of script would not run. Thus if you get back a 'nil', you can check to see if that is due to an error or no data. Whenever a Command Lua function gets an error, it will normally return a 'nil', and the error message will be available as a Lua global variables '_errmsg_' will have the last error message, '_errfnc_' the Command Lua function that gave the error, and '_errnum_' the error code (0 is no error, and any value >0 will be an error). While this may be okay in most cases, it is not often desired. Usually when a Lua script fails, an error is thrown that ends the script at that point. These cover any special considerations for the data, such as longitude/latitude degrees, DMS, N/S, E/W, etc. The particular wrapper Set(.) function is preferred as some validation is performed on the input to ensure that it is within the bounds of the field being updated. This information can be usually modified either directly (object.field) or by a wrapper Set(.) function. These define the information that is returned from some functions. Thus including the side, it will only check the units on that side for a match. When using just the name, usually the first matching name is returned. And as a last option, just the name which search all units in the scenario. If not, then the side and name for a more limited search. When selecting units, it is preferrable to use the GUID as the identifier for a precise match. Other properties may be included in the 'selector' such as when updating an existing table. In the case of functions that 'add' things, these are also key elements to the adding process. These define the information required as part of the 'select' process for the functions. However, when accessing the properties through the module functions below, both the keyword/property and the value are case insensitive the code will worry about matching them up.
mission.SISH=true which is a shortcut for scrub_if_side_human) which will be documented below.
See pairs in Lua's reference manual and next in Lua's reference manual for more details.When accessing object properties directly as in 'unit.name', the property should be in lower which will match the Lua generated code.
So using next is essentially a more manual version of pairs. Like pairs there is no specified order for traversal. Iterating a numeric table in reverse order is easy: for i = #numeric_table, 1, -1 doĪ final way to iterate over tables is to use the next selector in a generic for loop. Of course, the following also works for a table that is a proper sequence: for i = 1, #numeric_table do (See the section on "Avoiding gaps in tables used as arrays" for more information.) For example: table_with_holes = for index, value in ipairs(numeric_table) doīe warned that iteration using ipairs() will not work as you might want on few occasions: The ipairs function will always iterate from table, table, etc. for key, value in pairs(input_table) doįor tables using numeric keys, Lua provides an ipairs function. When iterating with pairs there is no specified order for traversal, even if the keys of the table are numeric. The Lua standard library provides a pairs function which iterates over the keys and values of a table.