ZScript global variables

From ZDoom Wiki
Jump to: navigation, search
Note: This feature is for ZScript only.

ZScript possesses several global structs accessible by classes.

Type Name Writable? Use/meaning
int validcount yes Internal variable used to avoid processing of the same data during one render frame.
bool multiplayer no Set to true if the game is networked.
LevelLocals level - Contains various level-related data, for example level's time, level and map name, settings and statistics.
DehInfo deh - Internal values used by DeHackEd-parsing code.
PlayerInfo[] players - List of all players in the level.
bool[] playeringame no An array that defines whether the specified PlayerInfo structure in players[] is set.
EGameAction gameaction yes Deeply internal variable used to get/set the current engine state.
WARNING: Do NOT use this unless you know GameAction works!
int consoleplayer no The player that owns the current client.
Weapon WP_NOCHANGE no An internal constant to describe the case when PlayerInfo.PendingWeapon doesn't have a value.

Creating Global Variables

To create global variables, create a thinker class with a static function to find and return one in existence, if there are any.
If you want the variable to persist across levels, change all instances of STAT_INFO in the code below to STAT_STATIC.

class MyGlobalVariables : Thinker
	int testVar;

	MyGlobalVariables Init()
		return self;

	static MyGlobalVariables Get()
		ThinkerIterator it = ThinkerIterator.Create("MyGlobalVariables",STAT_INFO);
		let p = MyGlobalVariables(it.Next());
		if (p == null)
			p = new("MyGlobalVariables").Init();
		return p;

Then, in the class wishing to access it:

let Tracker = MyGlobalVariables.Get();
if (Tracker)