Local

Category: Variables
Since engine version: 4.6.5.0 CP (extended in 4.9.1.0 GWE)

Description

Returns the value of an object local variable (as reference). Each object can hold any number of local variables. This are stored in the object until the object is deleted. A newly created local variable always has the value 0.

Syntax

any& Local (int iVarIndex, object pObj);

Parameters

iVarIndex:
Index of the variable to be accessed. Any non-negative number is allowed.
pObj:
[optional] Object holding the variable.

Remark

Since Local() returns a reference, the variable can be modified using operators such as Local(0) = 20 or Local(1)++
Where possible, a local named variable should be used instead of a local variable.

Example

/* Objektscript */
Hit:
	Local(0) = 1;
	Local(1) = 10;
	return(1);
Timer:
	if(Local(0) == 0) return();
	// Geräusch machen
	Sound("Fuse");
	// Variable herunterzählen
	Local(1)--;
	// Anzeigen
	Message(" %d ", Local(1));
	// Zeit um?
	if(Local(1) == 0)
		// Explosion!
		Explode(50);
	return();
				
This script is invoked through the engine callback 'Hit' which occurs when the object hits the ground.
The script sets the local variable 0 to value 1 and the variable 1 to value 10.
The second script function is called 'Timer' and should be called periodically (see Timer entry in DefCore). This function will check whether the object has already hit the ground (Local(0) ist set). If this is the case, a sound is played and the counter variable 1 is decreased. When the counter reaches zero, the object explodes. For example this could be a timed grenade activated by impact.
See also: Global, GlobalN, LocalN, SetGlobal, SetLocal, SetVar, Var, VarN
PeterW, November 2001