Magic Variables

From Bohemia Interactive Community
Revision as of 08:21, 3 May 2018 by Lou Montana (talk | contribs) (Add more details thanks to commy2 and sldt1ck - TODO: merge this here)
Jump to navigation Jump to search

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


See also: this


Usage

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

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

_thisEventHandler

Since Arma 3 v.1.63.137807, the script handle (not the EH index!) for Event Handlers added with addEventHandler or addMPEventHandler.

_pos,_alt,_shift,_units

See onMapSingleClick

_id,_uid,_name,_jip,_owner

See onPlayerConnected