Magic Variables

From Bohemia Interactive Community
(Redirected from this)
Jump to navigation Jump to search

Magic variables are engine-maintained variables that serve a specific purpose within a given scope and are often used by the engine to provide data to a script or code fragment.
They are usually no longer present after leaving the scope (e.g. after code execution or after a forEach-statement).


Used to make the arguments of a script call (call, exec, execVM, spawn) visible and accessible to the script. Also used by Event Handlers to provide parameters.


Represents the current element during iteration with apply, count, configClasses, configProperties, findIf, forEach and select.


Iterating over a HashMap with forEach will return the key as _x and the value as _y.


Exception handling using a try-catch-statement declares this variable which contains details about the thrown exception in the try-block.


Not engine-maintained, but added by functions_f/initFunctions.sqf – see scriptName.

Within a Function, the TAG_fnc_functionName function name (e.g. "myTag_fnc_myFunction").


Not engine-maintained, but added by functions_f/initFunctions.sqf – see scriptName.

Within a Function, the name of the function that called the current function (same as _fnc_scriptName if the function was not called by another function).


Represents the (zero-based) index of a forEach- / forEachReversed-loop.


Available in HashMapObject methods. Contains the HashMapObject instance that the method was invoked on (see createHashMapObject).


Additional Event Handler arguments available with addMissionEventHandler.


The name of the Event added with addEventHandler, addMPEventHandler, addMissionEventHandler,addUserActionEventHandler, ctrlAddEventHandler and displayAddEventHandler, as well as for config types EHs.


The index for Event Handlers added with addEventHandler, addMPEventHandler, addMissionEventHandler, addUserActionEventHandler, ctrlAddEventHandler and displayAddEventHandler.


The FSM ID for FSMs executed with execFSM.


The Script Handle of a script started with execVM, call or spawn.


The index for Scripted Event Handlers added with BIS_fnc_addScriptedEventHandler.


SQS only.

The time elapsed since the script started running.


  • Addon Config Files (e.g. UserActions, onInit, etc.): The object to which the entry belongs.
  • Dialogs: The player unit that activated control (e.g. via mouseEnter). false if non-activated.
  • Object Init Fields: The object to which the init field belongs.
  • Triggers:
    • Condition: The Boolean return value of the Trigger's condition (e.g. "East Not Present").
    • On Activation and On Deactivation: Seems to always return false.
  • Waypoints:
    • Condition, On Activation and On Deactivation: The group leader that completed the waypoint (or the driver, if the waypoint is assigned to a vehicle).


  • Triggers:
    • Accessible in the Condition, On Activation and On Deactivation code.
    • Defines an array of objects that have been detected by the trigger (same as what is returned by the list command).
    • Seems to be undefined in the On Deactivation expression and should not be used. It will either be an empty array, or possibly the contents of a different trigger.
  • Waypoints:
    • Accessible within the Condition or On Activation code.
    • Defines an array containing all group members that completed the waypoint.


Refers to the trigger object itself - accessible within the Condition, On Activation and On Deactivation code.