{"name":"Magic Variables","title":"Magic Variables","type":"topic","url":"https://community.bistudio.com/wiki/Magic_Variables","revid":378809,"updated":"2026-06-30T19:25:43Z","aliases":["fnc scriptName","forEachIndex","this","thisActivator","thisArgs","thisList","thisScript","thisTrigger","thisargs","x","y"],"markdown":"__NOEDITSECTION__\nMagic 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.\n\nThey are usually no longer present after leaving the scope (e.g. after code execution or after a forEach-statement).\n\n#### _this\n\nUsed 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.\n\n#### _x\n\nRepresents the current element during iteration with apply, count, configClasses, configProperties, findIf, forEach and select.\n\n#### _y (Arma 3 v2.02)\n\nIterating over a HashMap with forEach will return the key as _x and the value as _y.\n\n#### _exception (Armed Assault v1.00)\n\nException handling using a try-catch-statement declares this variable which contains details about the thrown exception in the try-block.\n\n#### _fnc_scriptName (Arma 3 v1.00)\n\n> [!NOTE]\n> Not engine-maintained, but added by `functions_f/initFunctions.sqf` – see scriptName.\n\nWithin a Function, the `TAG_fnc_functionName` function name (e.g. `\"myTag_fnc_myFunction\"`).\n\n#### _fnc_scriptNameParent (Arma 3 v1.00)\n\n> [!NOTE]\n> Not engine-maintained, but added by `functions_f/initFunctions.sqf` – see scriptName.\n\nWithin 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).\n\n#### _forEachIndex (Arma 2: Operation Arrowhead v1.55)\n\nRepresents the (zero-based) index of a forEach- / forEachReversed-loop.\n\n#### _self (Arma 3 v2.14)\n\nAvailable in HashMapObject methods. Contains the HashMapObject instance that the method was invoked on (see createHashMapObject).\n\n#### _thisArgs (Arma 3 v2.04)\n\nAdditional Event Handler arguments available with addMissionEventHandler.\n\n#### _thisEvent (Arma 3 v2.06)\n\nThe name of the Event added with addEventHandler, addMPEventHandler, addMissionEventHandler,addUserActionEventHandler, ctrlAddEventHandler and displayAddEventHandler, as well as for config types EHs.\n\n#### _thisEventHandler (Arma 3 v1.64)\n\nThe index for Event Handlers added with addEventHandler, addMPEventHandler, addMissionEventHandler, addUserActionEventHandler, ctrlAddEventHandler and displayAddEventHandler.\n\n#### _thisFSM (Arma 3 v1.54)\n\nThe FSM ID for FSMs executed with execFSM.\n\n#### _thisScript (Arma 3 v1.54)\n\nThe Script Handle of a script started with execVM, call or spawn.\n\n#### _thisScriptedEventHandler (Arma 3 v1.68)\n\nThe index for Scripted Event Handlers added with BIS_fnc_addScriptedEventHandler.\n\n#### _time\n\n> [!WARNING]\n> SQS only.\n\nThe time elapsed since the script started running.\n\n#### this\n\n- **Addon Config Files** (e.g. UserActions, onInit, etc.)**:** The object to which the entry belongs.\n- **Dialogs:** The player unit that activated control (e.g. via mouseEnter). false if non-activated.\n- **Object Init Fields:** The object to which the init field belongs.\n- **Triggers:**\n  - *Condition*: The Boolean return value of the Trigger's condition (e.g. \"East Not Present\").\n  - *On Activation* and *On Deactivation*: Seems to always return false.\n- **Waypoints:**\n  - *Condition*, *On Activation* and *On Deactivation*: The group leader that completed the waypoint (or the driver, if the waypoint is assigned to a vehicle).\n\n#### thisList\n\n- **Triggers:**\n  - Accessible in the *Condition*, *On Activation* and *On Deactivation* code.\n  - Defines an array of objects that have been detected by the trigger (same as what is returned by the list command).\n  - 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.\n- **Waypoints:**\n  - Accessible within the *Condition* or *On Activation* code.\n  - Defines an array containing all group members that completed the waypoint.\n\n#### thisTrigger\n\nRefers to the trigger object itself - accessible within the *Condition*, *On Activation* and *On Deactivation* code.\n\n#### thisActivator (Arma 3 v2.22)\n\nRefers to an Object, which activated this trigger. Default: the trigger Object itself.","sections":[{"heading":null,"level":1,"markdown":"__NOEDITSECTION__\nMagic 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.\n\nThey are usually no longer present after leaving the scope (e.g. after code execution or after a forEach-statement)."},{"heading":"_this","level":4,"markdown":"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."},{"heading":"_x","level":4,"markdown":"Represents the current element during iteration with apply, count, configClasses, configProperties, findIf, forEach and select."},{"heading":"_y (Arma 3 v2.02)","level":4,"markdown":"Iterating over a HashMap with forEach will return the key as _x and the value as _y."},{"heading":"_exception (Armed Assault v1.00)","level":4,"markdown":"Exception handling using a try-catch-statement declares this variable which contains details about the thrown exception in the try-block."},{"heading":"_fnc_scriptName (Arma 3 v1.00)","level":4,"markdown":"> [!NOTE]\n> Not engine-maintained, but added by `functions_f/initFunctions.sqf` – see scriptName.\n\nWithin a Function, the `TAG_fnc_functionName` function name (e.g. `\"myTag_fnc_myFunction\"`)."},{"heading":"_fnc_scriptNameParent (Arma 3 v1.00)","level":4,"markdown":"> [!NOTE]\n> Not engine-maintained, but added by `functions_f/initFunctions.sqf` – see scriptName.\n\nWithin 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)."},{"heading":"_forEachIndex (Arma 2: Operation Arrowhead v1.55)","level":4,"markdown":"Represents the (zero-based) index of a forEach- / forEachReversed-loop."},{"heading":"_self (Arma 3 v2.14)","level":4,"markdown":"Available in HashMapObject methods. Contains the HashMapObject instance that the method was invoked on (see createHashMapObject)."},{"heading":"_thisArgs (Arma 3 v2.04)","level":4,"markdown":"Additional Event Handler arguments available with addMissionEventHandler."},{"heading":"_thisEvent (Arma 3 v2.06)","level":4,"markdown":"The name of the Event added with addEventHandler, addMPEventHandler, addMissionEventHandler,addUserActionEventHandler, ctrlAddEventHandler and displayAddEventHandler, as well as for config types EHs."},{"heading":"_thisEventHandler (Arma 3 v1.64)","level":4,"markdown":"The index for Event Handlers added with addEventHandler, addMPEventHandler, addMissionEventHandler, addUserActionEventHandler, ctrlAddEventHandler and displayAddEventHandler."},{"heading":"_thisFSM (Arma 3 v1.54)","level":4,"markdown":"The FSM ID for FSMs executed with execFSM."},{"heading":"_thisScript (Arma 3 v1.54)","level":4,"markdown":"The Script Handle of a script started with execVM, call or spawn."},{"heading":"_thisScriptedEventHandler (Arma 3 v1.68)","level":4,"markdown":"The index for Scripted Event Handlers added with BIS_fnc_addScriptedEventHandler."},{"heading":"_time","level":4,"markdown":"> [!WARNING]\n> SQS only.\n\nThe time elapsed since the script started running."},{"heading":"this","level":4,"markdown":"- **Addon Config Files** (e.g. UserActions, onInit, etc.)**:** The object to which the entry belongs.\n- **Dialogs:** The player unit that activated control (e.g. via mouseEnter). false if non-activated.\n- **Object Init Fields:** The object to which the init field belongs.\n- **Triggers:**\n  - *Condition*: The Boolean return value of the Trigger's condition (e.g. \"East Not Present\").\n  - *On Activation* and *On Deactivation*: Seems to always return false.\n- **Waypoints:**\n  - *Condition*, *On Activation* and *On Deactivation*: The group leader that completed the waypoint (or the driver, if the waypoint is assigned to a vehicle)."},{"heading":"thisList","level":4,"markdown":"- **Triggers:**\n  - Accessible in the *Condition*, *On Activation* and *On Deactivation* code.\n  - Defines an array of objects that have been detected by the trigger (same as what is returned by the list command).\n  - 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.\n- **Waypoints:**\n  - Accessible within the *Condition* or *On Activation* code.\n  - Defines an array containing all group members that completed the waypoint."},{"heading":"thisTrigger","level":4,"markdown":"Refers to the trigger object itself - accessible within the *Condition*, *On Activation* and *On Deactivation* code."},{"heading":"thisActivator (Arma 3 v2.22)","level":4,"markdown":"Refers to an Object, which activated this trigger. Default: the trigger Object itself."}],"categories":["Scripting Topics"],"groups":["Scripting"]}