ZScript custom properties

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

Custom properties can be defined in a base class for classes to utilize within the Default { } block.

property PropertyName: LocalVar1, LocalVar2, ...

The LocalVar(s) can be anything except arrays, as they are not yet supported. They must be defined in the base class's global namespace outside states and Default block.

Finally, apply the following syntax to inheriting classes: <NameOfBaseClass>.PropertyName <LocalVar1>, <LocalVar2>, ...

It's also possible to retrieve the default value assigned to the property, including built-in actor properties.

Speed = Default.Speed;
PuzzleItemNumber = Default.PuzzleItemNumber;


From PuzzleItem:

class PuzzleItem : Inventory
	int PuzzleItemNumber;
	String PuzzFailMessage;
	property Number: PuzzleItemNumber;
	property FailMessage: PuzzFailMessage;

		Inventory.UseSound "PuzzleSuccess";
		Inventory.PickupSound "misc/i_pkup";
		PuzzleItem.FailMessage("$TXT_USEPUZZLEFAILED"); //Setting up its own default after being defined.
	// ...

This is an example using the Health class and Doom's Medikit. In the Health class, the following are defined:

class Health : Inventory
	int LowHealth;
	String LowHealthMessage;
	property LowMessage: LowHealth, LowHealthMessage;
	// ...

And in the Medikit:

class Medikit : Health
		Inventory.Amount 25;
		Inventory.PickupMessage "$GOTMEDIKIT";
		Health.LowMessage 25, "$GOTMEDINEED"; //<--------- The custom property. Uses LowHealth, and then the LowHealthMessage.
		MEDI A -1;