Magic Variables: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
(Add _thisScript and categories)
Line 2: Line 2:
=== 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).


=== Uses ===
=== Uses ===
* '''_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 [[forEach]] or a [[count]]
* '''_forEachIndex''': represents the (zero-based) index of a [[forEach]] '''_x'''
* '''thisList''', '''thisTrigger''': variable defined by [[Triggers]], which are however only accessible within the activation or deactivation script.
* '''_exception''': [Exception handling]] using a [[try]]..[[catch]] statement declares this variable which contains details about the [[throw|thrown]] exception in the try block
* '''_thisScript''': is the [[spawn|spawned]] script handle from within itself since {{arma3}}


*The most frequently used magic variable probably is <tt>_[[this]]</tt>, which is used to make arguments of a script call ([[call]], [[exec]], [[execVM]], [[spawn]]) visible and accessible to the script.
[[Category: Scripting Topics]]
*Other uses of magic variables can be seen in [[forEach]], where the current element can be accessed via <tt>[[_x]]</tt> and the current index with <tt>[[_forEachIndex]]</tt>.
[[Category: Operation Flashpoint: Editing]]
*In the condition of the extended syntax of [[count]] variable <tt>_x</tt> refers to the current tested element.
[[Category: ArmA: Editing‏‎]]
*[[Triggers]] also define <tt>[[thisList]]</tt> and <tt>[[thisTrigger]]</tt>, which is however only accessible within the activation or deactivation script.
[[Category: ArmA 2: Editing‏‎]]
*[[Exception handling]] using a [[try]]..[[catch]] statement usually declare a magic variable named <tt>_exception</tt>, which contains details about the exception [[throw]]n in the try-block.
[[Category: Arma 3: Editing]]

Revision as of 00:41, 3 May 2018

Template:Stub

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

Uses

  • _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 forEach or a count
  • _forEachIndex: represents the (zero-based) index of a forEach _x
  • thisList, thisTrigger: variable defined by Triggers, which are however only accessible within the activation or deactivation script.
  • _exception: [Exception handling]] using a try..catch statement declares this variable which contains details about the thrown exception in the try block
  • _thisScript: is the spawned script handle from within itself since Arma 3