Magic Variables: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(Vistual appearance of the page and some formatting)
No edit summary
(29 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{TOC|side}}
__NOEDITSECTION__
__NOEDITSECTION__
== Introduction ==
'''Magic variables''' are engine-maintained [[Variables|variables]] that serve a specific purpose within a given scope and are often used by the engine to push data to a given [[Script File|script]] or [[Code|code]] fragment.<br>They are usually no longer present after leaving the scope (e.g. after code execution or after a [[forEach]] statement).


'''Magic variables''' are engine maintained [[Variables|variables]] that serve a specific purpose within a given scope and are often used by the engine to push data to a given [[Script (File)|script]] or [[Code|code]] fragment.<br>They are usually no longer present after leaving the scope (e.g. after code execution or after a [[forEach]] statement).


{{Cfg ref|start}}
{{ConfigPage|start}}
{{Cfg ref|abc}}
{{ConfigPage|abc}}
== Generic ==
==== _this ====
==== _this ====
Is used to make arguments of a script call ([[call]], [[exec]], [[execVM]], [[spawn]]) visible and accessible to the script.
Is used to make arguments of a script call ([[call]], [[exec]], [[execVM]], [[spawn]]) visible and accessible to the script, also used in Event Handlers to pass appropriate params.




Line 15: Line 14:




<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma|1.00}}</div>
{{ArgTitle|4|_y|{{GVI|arma3|2.02}}}}
==== _exception ====
Iterating over a [[HashMap]] with [[forEach]] will return the key as [[#x|_x]] and the value as [[#y|_y]].
</div>
 
[[Exception handling]] using a [[try]]..[[catch]] statement declares this variable which contains details about the [[throw|thrown]] exception in the try block.
 
{{ArgTitle|4|_exception|{{GVI|arma1|1.00}}}}
[[Exception handling]] using a [[try]]-[[catch]] statement declares this variable which contains details about the [[throw|thrown]] exception in the try block.




==== _forEachIndex ====
==== _forEachIndex ====
Represents the (zero-based) index of a [[forEach]] '''x'''.
Represents the (zero-based) index of a [[forEach]] [[#x|_x]] element.




<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.54}}</div>
{{ArgTitle|4|_thisArgs|{{GVI|arma3|2.04}}}}
==== _thisEventHandler ====
Additional Event Handler arguments available with [[addMissionEventHandler]]
</div>
The script handle (not the EH index!) for Event Handlers added with [[addEventHandler]] or [[addMPEventHandler]].




<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.54}}</div>
{{ArgTitle|4|_thisEventHandler|{{GVI|arma3|1.54}}}}
==== _thisFSM ====
The index for Event Handlers added with [[addEventHandler]], [[addMPEventHandler]], [[addMissionEventHandler]] or [[addUserActionEventHandler]].
</div>
 
 
{{ArgTitle|4|_thisScriptedEventHandler|{{GVI|arma3|1.68}}}}
The index for Scripted Event Handlers added with [[BIS_fnc_addScriptedEventHandler]].
 
 
{{ArgTitle|4|_thisEvent|{{GVI|arma3|2.06}}}}
The name of the Event added with [[addEventHandler]], [[addMPEventHandler]], [[addMissionEventHandler]] or [[addUserActionEventHandler]], as well as for config types EHs.
 
 
{{ArgTitle|4|_thisFSM|{{GVI|arma3|1.54}}}}
The [[FSM]] id for FSMs executed with [[execFSM]].
The [[FSM]] id for FSMs executed with [[execFSM]].




<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.54}}</div>
{{ArgTitle|4|_thisScript|{{GVI|arma3|1.54}}}}
==== _thisScript ====
The [[execVM]]ed, [[call]]ed or [[spawn]]ed [[Script Handle|script handle]] from within itself.
</div>
 
The [[call|called]] or [[spawn|spawned]] script handle from within itself.
 
==== _time ====
'''[[SQS Syntax|SQS]] ONLY.''' The time elapsed since the script started running.
 
 
{{ArgTitle|4|_fnc_scriptName|{{GVI|arma3|1.00}}}}
{{Feature|Informative|not engine-maintained, but added by functions_f/'''initFunctions.sqf''' script – see [[scriptName]]}}
From within a [[:Category:Functions|Function]], the '''TAG_fnc_functionName''' function name as string (e.g. "myTag_fnc_myFunction")
 
 
{{ArgTitle|4|_fnc_scriptNameParent|{{GVI|arma3|1.00}}}}
{{Feature|Informative|not engine-maintained, but added by functions_f/'''initFunctions.sqf''' script – see [[scriptName]]}}
From within a [[:Category:Functions|Function]], name of the function that called the current one ([[#fnc_scriptName|_fnc_scriptName]] used when not defined)




==== this ====
==== this ====
* '''In Addons' config files''' (e.g. UserActions, onInit, etc.): The object the entry belongs to
* '''In Addons' config files''' (e.g. UserActions, onInit, etc.): The object to which the entry belongs
* '''In Dialogs''': The player unit that activated control (e.g. via mouseEnter). [[false]] if non-activated
* '''In Dialogs''': The player unit that activated control (e.g. via mouseEnter). [[false]] if non-activated
* '''In Object's "Init" line:''' The object the init line belongs to
* '''In Object's "Init" line:''' The object to which the init line belongs
* '''In Triggers'''
* '''In Triggers'''
** ''"Condition" line'': The [[Boolean]] return value of the [[Mission Editor: Triggers|trigger]]'s conditions (e.g. "East Not Present" etc)
** ''"Condition" line'': The [[Boolean]] return value of the [[Mission Editor: Triggers|trigger]]'s conditions (e.g. "East Not Present" etc)
** ''"On Activation/Deactivation" line'': Seems to always return false
** ''"On Activation/Deactivation" line'': Seems to always return [[false]]
* '''In Waypoints'''
* '''In Waypoints'''
** ''"Condition" or "On Activation/Deactivation" line'': The group leader that completed the respective waypoint (or driver, if waypoint is assigned to a vehicle)
** ''"Condition" or "On Activation/Deactivation" line'': The group leader that completed the respective waypoint (or driver, if waypoint is assigned to a vehicle)
Line 58: Line 79:
* Triggers:
* Triggers:
** accessible within the '''Condition''', '''On Activation''' or '''On Deactivation''' script
** accessible within the '''Condition''', '''On Activation''' or '''On Deactivation''' script
** defines an array of objects that are currently fulfilling the trigger's condition (same as what is returned by the [[list]] command)
** defines an array of objects that have been detected by the trigger (same as what is returned by the [[list]] command)
** '''thisList''' in a trigger's '''On Deactivation''' field seems to be undefined, and should not be used. It will either return an empty array, or possibly the contents of a different trigger.
** '''thisList''' in a trigger's '''On Deactivation''' field seems to be undefined, and should not be used. It will either return an empty array, or possibly the contents of a different trigger.
* Waypoints:
* Waypoints:
** accessible within the '''Condition''' or ''On Activation''' script
** accessible within the '''Condition''' or '''On Activation''' script
** defines an array containing all group members that completed the respective waypoint
** defines an array containing all group members that completed the respective waypoint




==== thisTrigger ====
==== thisTrigger ====
Refers to the [[Triggers|trigger]] object itself.
Refers to the [[Triggers|trigger]] object itself - accessible within the '''Condition''', '''On Activation''' or '''On Deactivation''' script.
 
 
== Specifics ==
 
<div><div style="float: left; margin-right: 0.5em;">{{GVI|ofpr|1.85}}</div>
==== onMapSingleClick: _pos,_alt,_shift,_units ====
</div>
*See [[onMapSingleClick]]


{{ConfigPage|end}}


<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma|1.00}}</div>
==== onPlayerConnected: _id,_uid,_name,_jip,_owner ====
</div>
*See [[onPlayerConnected]]


[[Category: Scripting Topics]]
[[Category: Scripting Topics]]
[[Category: Operation Flashpoint: Editing]]
[[Category: ArmA: Editing‏‎]]
[[Category: ArmA 2: Editing‏‎]]
[[Category: Arma 3: Editing]]

Revision as of 14:51, 17 February 2022

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


_this

Is used to make arguments of a script call (call, exec, execVM, spawn) visible and accessible to the script, also used in Event Handlers to pass appropriate params.


_x

Represents the current element during a loop with: apply, count, configClasses, configProperties, findIf, forEach, select.


_y

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


_exception

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


_forEachIndex

Represents the (zero-based) index of a forEach _x element.


_thisArgs

Additional Event Handler arguments available with addMissionEventHandler


_thisEventHandler

The index for Event Handlers added with addEventHandler, addMPEventHandler, addMissionEventHandler or addUserActionEventHandler.


_thisScriptedEventHandler

The index for Scripted Event Handlers added with BIS_fnc_addScriptedEventHandler.


_thisEvent

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


_thisFSM

The FSM id for FSMs executed with execFSM.


_thisScript

The execVMed, called or spawned script handle from within itself.


_time

SQS ONLY. The time elapsed since the script started running.


_fnc_scriptName

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

From within a Function, the TAG_fnc_functionName function name as string (e.g. "myTag_fnc_myFunction")


_fnc_scriptNameParent

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

From within a Function, name of the function that called the current one (_fnc_scriptName used when not defined)


this

  • In Addons' config files (e.g. UserActions, onInit, etc.): The object to which the entry belongs
  • In Dialogs: The player unit that activated control (e.g. via mouseEnter). false if non-activated
  • In Object's "Init" line: The object to which the init line belongs
  • In Triggers
    • "Condition" line: The Boolean return value of the trigger's conditions (e.g. "East Not Present" etc)
    • "On Activation/Deactivation" line: Seems to always return false
  • In Waypoints
    • "Condition" or "On Activation/Deactivation" line: The group leader that completed the respective waypoint (or driver, if waypoint is assigned to a vehicle)


thisList

Variable defined by Triggers and Waypoints:

  • Triggers:
    • accessible within the Condition, On Activation or On Deactivation script
    • defines an array of objects that have been detected by the trigger (same as what is returned by the list command)
    • thisList in a trigger's On Deactivation field seems to be undefined, and should not be used. It will either return an empty array, or possibly the contents of a different trigger.
  • Waypoints:
    • accessible within the Condition or On Activation script
    • defines an array containing all group members that completed the respective waypoint


thisTrigger

Refers to the trigger object itself - accessible within the Condition, On Activation or On Deactivation script.