Magic Variables: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(clarified thisList)
m (Add category)
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{SideTOC}}
__NOEDITSECTION__
__NOEDITSECTION__
{{Cfg ref|start}}
{{Cfg ref|abc}}
== 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).




== Generic ==
{{Cfg ref|start}}
{{Cfg ref|abc}}
==== _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.
Line 15: Line 14:




<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma|1.00}}</div>
{{ArgTitle|_exception|4|{{GVI|arma|1.00}}}}
==== _exception ====
</div>
[[Exception handling]] using a [[try]]-[[catch]] statement declares this variable which contains details about the [[throw|thrown]] exception in the try block.
[[Exception handling]] using a [[try]]-[[catch]] statement declares this variable which contains details about the [[throw|thrown]] exception in the try block.


Line 25: Line 22:




<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.54}}</div>
{{ArgTitle|_thisEventHandler|4|{{GVI|arma3|1.54}}}}
==== _thisEventHandler ====
</div>
The index for Event Handlers added with [[addEventHandler]], [[addMPEventHandler]] or [[addMissionEventHandler]].
The index for Event Handlers added with [[addEventHandler]], [[addMPEventHandler]] or [[addMissionEventHandler]].




<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.54}}</div>
{{ArgTitle|_thisFSM|4|{{GVI|arma3|1.54}}}}
==== _thisFSM ====
</div>
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|_thisScript|4|{{GVI|arma3|1.54}}}}
==== _thisScript ====
The [[call|called]] or [[spawn|spawned]] [[Script (Handle)|script handle]] from within itself.
</div>
The [[call|called]] or [[spawn|spawned]] script handle from within itself.




<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.00}}</div>
==== _time ====
==== _fnc_scriptName ====
'''[[SQS]] ONLY.''' The time elapsed since the script started running.
</div>
 
 
{{ArgTitle|_fnc_scriptName|4|{{GVI|arma3|1.00}}}}
{{note|not engine-maintained, but added by functions_f/'''initFunctions.sqf''' script – see [[scriptName]]}}
{{note|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")
From within a [[:Category:Functions|Function]], the '''TAG_fnc_functionName''' function name as string (e.g. "myTag_fnc_myFunction")




<div><div style="float: left; margin-right: 0.5em;">{{GVI|arma3|1.00}}</div>
{{ArgTitle|_fnc_scriptNameParent|4|{{GVI|arma3|1.00}}}}
==== _fnc_scriptNameParent ====
</div>
{{note|not engine-maintained, but added by functions_f/'''initFunctions.sqf''' script – see [[scriptName]]}}
{{note|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)
From within a [[:Category:Functions|Function]], name of the function that called the current one ([[#fnc_scriptName|_fnc_scriptName]] used when not defined)
Line 75: Line 66:
** '''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]]


{{Cfg ref|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: Operation Flashpoint: Editing]]
[[Category: ArmA: Editing‏‎]]
[[Category: ArmA: Editing‏‎]]
[[Category: ArmA 2: Editing‏‎]]
[[Category: Arma 2: Editing‏‎]]
[[Category: Arma 3: Editing]]
[[Category: Arma 3: Editing‏‎]]

Revision as of 15:02, 20 June 2020

Template:SideTOC

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).


Template:Cfg ref Template:Cfg ref

_this

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.


-wrong parameter ("Arma") defined!-1.00

4

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.


4

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


4

The FSM id for FSMs executed with execFSM.


4

The called or spawned script handle from within itself.


_time

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


4

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


4

Template:note 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 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 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.

Template:Cfg ref