Module ScenEdit

Lua is a case sensitive language.

When accessing object properties directly as in ‘unit.name’, the property should be in lower which will match the Lua generated code. There may be a few special cases (e.g. mission.SISH=true which is a shortcut for scrub_if_side_human) which will be documented below.

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.

Selector
These define the information required as part of the ‘select’ process for the functions. In the case of functions that ‘add’ things, these are also key elements to the adding process. Other properties may be included in the ‘selector’ such as when updating an existing table.

When selecting units, it is preferable to use the GUID as the identifier for a precise match. If not, then the side and name for a more limited search. And as a last option, just the name which search all units in the scenario. When using just the name, usually the first matching name is returned. This is okay if the names are unique. Thus including the side, it will only check the units on that side for a match.

Wrapper
These define the information that is returned from some functions. This information can be usually modified either directly (object.field) or by a wrapper Set(..) function. 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.

Data type
These cover any special considerations for the data, such as longitude/latitude; degrees, DMS, N/S, E/W, etc.

Error handling
Usually when a Lua script fails, an error is thrown that ends the script at that point. While this may be okay in most cases, it is not often desired. 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). Thus if you get back a ‘nil’, you can check to see if that is due to an error or no data.

Example:
without the new error handling, the script below would probably terminate after the SE_AddMission() and the rest of script would not run.

local mission = ScenEdit_AddMission('USA','Marker strike','strike',{type='land'})
if mission == nil then
 if _errnum_ ~= 0 then print('Failed to add:' .. _errmsg_) else print('Something else') end
else
 print(mission)
 do some more command lua stuff...
end

Note: Due to how errors are now handle from SR7, if a command fails in the console window, it will show an error. 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. 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. 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.

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. Which requires the designer to cater for the specific error conditions.

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.

Note also, that the Lua history log should also record the event script errors.

Selector

ActionUpdate Action update.
ConditionUpdate Condition update.
ContactSelector Contact selector.
DamageOptions Unit damage.
DoctrineSelector Selects a doctrine.
DoctrineWRASelector Selects a WRA doctrine.
EventTCAUpdate Event Trigger/Condition/Action update.
EventUpdate Event update.
NewMission New mission options.
NewUnit New unit selector.
ReferencePointSelector Reference point selector.
SideOption Side options.
SpecialAction Special action selector.
TriggerUpdate Trigger update.
UnitSelector Select a unit.
UpdateUnit Update unit sensor/mount/weapon selector.
UpdateUnitCargo Update unit cargo selector.
VPContactSelector Contact selector.
Weapon2Magazine Select magazine and weapon.
Weapon2Mount Select mount and weapon.

Wrapper/Descriptor

AttackOptions Attack options.
Contact Contact details.
Doctrine Doctrine options.
DoctrineWRA WRA Doctrine options.
Event Event details.
Group Group details.
Loadout Loadout.
Mission Mission.
ReferencePoint Reference point information.
RefuelOptions Unit refueling options.
Side Side perspective.
Unit Represents a active unit.
Zone Exclusion/No navigation zone.

Data types

Altitude Altitude.
Arc Arcs.
DateTime DateTime.
KeyStore KeyStore.
Latitude Latitude.
LoadoutRole
LoadoutTimeOfDay
LoadoutWeather
Longitude Longitude.
Size Size.
Stance Stance/Posture.
TargetTypeWRA Target type.
TimeStamp TimeStamp.
WeaponDoctrine
WeaponType
Weather weather conditions.

Notes

WrapperFields List fields in a wrapper.

Functions

GetBuildNumber () Gets the exe build number.
GetScenarioTitle () Name of the scenario.
ScenEdit_AddExplosion (explosion) Detonates a warhead at a specified location.
ScenEdit_AddMission (SideNameOrId, MissionNameOrId, MissionType, MissionOptions) Add new mission.
ScenEdit_AddReferencePoint (descriptor) Add new reference point(s).
ScenEdit_AddReloadsToUnit (descriptor) Adds weapons into a mount.
ScenEdit_AddSide (table) Add side.
ScenEdit_AddUnit (unit) Adds a unit based on a descriptor.
ScenEdit_AddWeaponToUnitMagazine (descriptor) Adds weapons into a magazine.
ScenEdit_AddZone (sideName, zoneType, table) Add no-nav or exclusion zone.
ScenEdit_AssignUnitAsTarget (AUNameOrIDOrTable, MissionNameOrID) Assigns targets to a Strike mission.
ScenEdit_AssignUnitToMission (unitname, mission, escort) Assign a unit to a mission.
ScenEdit_AttackContact (attackerID, contactId, options) Attack a contact
ScenEdit_ClearKeyValue (key, forCampaign) Clears a key

..

ScenEdit_CurrentTime () Get the current scenario time.
ScenEdit_DeleteMission (SideNameOrId, MissionNameOrId) Delete mission.
ScenEdit_DeleteReferencePoint (selector) Delete a reference point.
ScenEdit_DeleteUnit (unit) Deletes unit.
ScenEdit_EndScenario () Ends the current scenario.
ScenEdit_EventX () Active Event
ScenEdit_ExecuteEventAction (EventDescriptionOrID) Execute a Lua Event action script.
ScenEdit_ExecuteSpecialAction (eventNameOrId) Execute a Lua Special action script
ScenEdit_ExportInst (side, unitList, fileData) Export unit(s) to an inst file.
ScenEdit_ExportMission (SideNameOrId, MissionNameOrId) Export mission parameters.
ScenEdit_FillMagsForLoadout (unit, loadoutid, quantity) Fill a unit's magazine(s) with aircraft stores
ScenEdit_GetContact (contact) Fetches a contact based on a selector.
ScenEdit_GetContacts (side) Contacts from a side.
ScenEdit_GetDoctrine (selector) Gets the doctrine of the designated object.
ScenEdit_GetDoctrineWRA (selector) Gets the WRA doctrine.
ScenEdit_GetEvent (EventDescriptionOrID, level) Gets the properties of an event.
ScenEdit_GetEvents (level) Gets all events.
ScenEdit_GetKeyValue (key, forCampaign) Gets the value for a key from the persistent key store.
ScenEdit_GetLoadout (loadoutinfo) Gets the loadout for a unit
ScenEdit_GetMission (SideNameOrId, MissionNameOrId) Get details of a mission.
ScenEdit_GetReferencePoints (selector) Get a set of reference point(s).
ScenEdit_GetScenHasStarted () Has the scenario started?
ScenEdit_GetScore (side) Get a given side's score.
ScenEdit_GetSideIsHuman (sidename) Returns true if side is played by a human player
ScenEdit_GetSideOptions (options) Get side options.
ScenEdit_GetSidePosture (sideA, sideB) Gets the posture of one side towards another.
ScenEdit_GetSpecialAction (action_info) Gets the properties of an existing special action.
ScenEdit_GetUnit (unit) Fetches a unit based on a selector.
ScenEdit_GetWeather () Get the current weather conditions.
ScenEdit_HostUnitToParent (host_info) Host/base
ScenEdit_ImportInst (side, filename) Imports an inst file.
ScenEdit_ImportMission (SideNameOrId, MissionNameOrId) Import mission parameters.
ScenEdit_InputBox (string) Open an input box with the passed prompt.
ScenEdit_KillUnit (unit) Kill unit.
ScenEdit_MsgBox (string, style) Show a message box with a passed string.
ScenEdit_PlayerSide () The player's current side.
ScenEdit_RefuelUnit (unitOptions) Cause unit to refuel.
ScenEdit_RemoveSide (table) Remove side from play.
ScenEdit_RemoveUnitAsTarget (AUNameOrIDOrTable, MissionNameOrID) Removes targets from a Strike mission.
ScenEdit_RunScript (script) Runs a script from a file.
ScenEdit_SetAction (options) Sets the attributes of an action.
ScenEdit_SetCondition (options) Sets the attributes of an condition.
ScenEdit_SetDoctrine (selector, doctrine) Set the doctrine of the designated object.
ScenEdit_SetDoctrineWRA (selector, options)

Sets the WRA doctrine.

ScenEdit_SetEMCON (type, name, emcon) Sets the EMCON of the selected object.
ScenEdit_SetEvent (EventDescriptionOrID, options) Sets the attributes of an event.
ScenEdit_SetEventAction (EventDescriptionOrID, options) Sets the attributes of a T/C/A.
ScenEdit_SetEventCondition (EventDescriptionOrID, options) Sets the attributes of a T/C/A.
ScenEdit_SetEventTrigger (EventDescriptionOrID, options) Sets the attributes of a T/C/A.
ScenEdit_SetKeyValue (key, value, forCampaign) Sets the value for a key in the persistent key store.
ScenEdit_SetLoadout (loadoutinfo) Sets the loadout for a unit
ScenEdit_SetMission (SideName, MissionNameOrId, MissionOptions) Set details for a mission.
ScenEdit_SetReferencePoint (descriptor) Update a reference point(s) with new values.
ScenEdit_SetScore (side, score, reason) Sets a given side's score.
ScenEdit_SetSideOptions (options) Set side options.
ScenEdit_SetSidePosture (sideAName, sideBName, posture) Set the posture of a side towards another.
ScenEdit_SetSpecialAction (action_info) Sets the properties of an existing special action.
ScenEdit_SetTime (new_time) Sets the scenario time (UTC).
ScenEdit_SetTrigger (options) Sets the attributes of a trigger.
ScenEdit_SetUnit (unit) Sets the properties of a unit that already exists.
ScenEdit_SetUnitDamage (options) Set unit damage.
ScenEdit_SetUnitSide (sidedesc) Changes the side of a unit
ScenEdit_SetWeather (temperature, rainfall, undercloud, seastate) Set the current weather conditions.
ScenEdit_SpecialMessage (side, message, location) Displays a special message consisting of the HTML text message to side `side.
ScenEdit_TransferCargo (fromUnit, toUnit, cargoList) Transfer cargo
ScenEdit_UnitC () Detected Contact
ScenEdit_UnitX () Activating Unit
ScenEdit_UnitY () Detecting Unit
ScenEdit_UnloadCargo (fromUnit, cargoList) Unload cargo
ScenEdit_UpdateUnit (options) Update items on a unit.
ScenEdit_UpdateUnitCargo (options) Update cargo on a unit.
ScenEdit_UseAttachment (attachment) Import an attachment into the scene.
ScenEdit_UseAttachmentOnSide (attachment, sidename) Use an attachment on a side (used for .inst files as attachments).
Tool_Bearing () Get bearing between points.
Tool_DumpEvents () Dump scenario events.
Tool_EmulateNoConsole () Emulates no console.
Tool_Range () Get range between points.
VP_ExportUnits (table, filename) Export unit details >
VP_GetContact (ContactGUID) Get contact details
VP_GetSide (side) Side information from player's perspective.
VP_GetUnit (ActiveOrContact) Get unit details
World_GetCircleFromPoint (table) Returns a circle around point.
World_GetElevation (location) Returns the elevation in meters of a given position
World_GetPointFromBearing (table) Returns a location based on bearing.

Tables

AAR AAR.
CargoMission CargoMission.
Component Component.
EMmatch EM matches
Emissions Contact emission
Explosion Defines the warhead to detonate.
Facility Facility.
FerryMission FerryMission.
Fuel Fuel.
FuelState Status of a fuel type.
HostUnit Requests that a unit be hosted/based to another
LatLon A Position on the map.
LoadoutInfo Information on a loadout to add/alter
Magazine Magazine.
MineClearMission MineClearMission.
MineMission MineMission.
Mount Mount.
PatrolMission PatrolMission.
SideContact Side's contact.
SideDescription Information on how to change a unit's side.
SideSelector Information to select a particular side.
SideUnit Side's unit.
StrikeMission StrikeMission.
SupportMission SupportMission.
WRA WRA settings.
Waypoint Waypoint
WeaponLoaded Weapon loads on mount or in magazine.
ZoneMarker Zone marker.

Selectors


ActionUpdate


ConditionUpdate