ZScript custom properties

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

(New from 2.4.0)

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

Examples

From PuzzleItem:

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

	Default
	{
		+NOGRAVITY
		+INVENTORY.INVBAR
		Inventory.DefMaxAmount;
		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
{
	Default
	{
		Inventory.Amount 25;
		Inventory.PickupMessage "$GOTMEDIKIT";
		Health.LowMessage 25, "$GOTMEDINEED"; //<--------- The custom property. Uses LowHealth, and then the LowHealthMessage.
	}
	States
	{
	Spawn:
		MEDI A -1;
		Stop;
	}
}