Magic Variables: Difference between revisions
Lou Montana (talk | contribs) (Add more details thanks to commy2 and sldt1ck - TODO: merge this here) |
Lou Montana (talk | contribs) (Merging this informations here) |
||
Line 1: | Line 1: | ||
__NOEDITSECTION__ | |||
== Introduction == | == 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. 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. They are usually no longer present after leaving the scope (e.g. after code execution or after a [[forEach]] statement). | ||
== Usage == | |||
=== Generic === | |||
==== _this ==== | ==== _this ==== | ||
probably the most frequently used magic variable, which is used to make arguments of a script call ([[call]], [[exec]], [[execVM]], [[spawn]]) visible and accessible to the script. | probably the most frequently used magic variable, which is used to make arguments of a script call ([[call]], [[exec]], [[execVM]], [[spawn]]) visible and accessible to the script. | ||
==== _x ==== | ==== _x ==== | ||
represents the current element during a loop with: [[apply]], [[count]], [[configClasses]], [[configProperties]], [[findIf]], [[forEach]], [[select]]. | represents the current element during a loop with: [[apply]], [[count]], [[configClasses]], [[configProperties]], [[findIf]], [[forEach]], [[select]]. | ||
<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma|1.00}}</div> | |||
==== _exception ==== | |||
</div> | |||
[[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|_x]]'''. | represents the (zero-based) index of a [[forEach]] [[#x|_x]]'''. | ||
==== | <div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.54}}</div> | ||
[ | ==== _thisEventHandler ==== | ||
</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> | |||
==== _thisFSM ==== | |||
</div> | |||
The FSM id for FSMs executed with [[execFSM]]. | |||
<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.54}}</div> | |||
==== _thisScript ==== | ==== _thisScript ==== | ||
</div> | |||
The [[call|called]] or [[spawn|spawned]] script handle from within itself. | |||
==== this ==== | |||
* '''In Addons' config files''' (e.g. UserActions, onInit, etc.): The object the entry belongs to | |||
* '''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 Triggers''' | |||
** ''"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 | |||
* '''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 are currently fulfilling the trigger's condition (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 [[Triggers|trigger]] object itself. | |||
=== Specifics === | |||
==== _pos,_alt,_shift,_units ==== | <div><div style="float: left; margin-right: 0.5em;">{{GVI|ofpr|1.85}}</div> | ||
==== onMapSingleClick: _pos,_alt,_shift,_units ==== | |||
</div> | |||
See [[onMapSingleClick]] | See [[onMapSingleClick]] | ||
==== _id,_uid,_name,_jip,_owner ==== | |||
<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma|1.00}}</div> | |||
==== onPlayerConnected: _id,_uid,_name,_jip,_owner ==== | |||
</div> | |||
See [[onPlayerConnected]] | See [[onPlayerConnected]] | ||
Revision as of 08:44, 3 May 2018
Introduction
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).
Usage
Generic
_this
probably the most frequently used magic variable, which is used to make arguments of a script call (call, exec, execVM, spawn) visible and accessible to the script.
_x
represents the current element during a loop with: apply, count, configClasses, configProperties, findIf, forEach, select.
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.
_thisEventHandler
The script handle (not the EH index!) for Event Handlers added with addEventHandler or addMPEventHandler.
_thisFSM
The FSM id for FSMs executed with execFSM.
_thisScript
The called or spawned script handle from within itself.
this
- In Addons' config files (e.g. UserActions, onInit, etc.): The object the entry belongs to
- 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 Triggers
- 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 are currently fulfilling the trigger's condition (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.
Specifics
onMapSingleClick: _pos,_alt,_shift,_units
See onMapSingleClick