[ZSCRIPT] How do I utilise Custom Properties?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Mikk-
Posts: 2273
Joined: Tue Jun 30, 2009 1:31 pm
Location: Somewhere off Kanagawa

[ZSCRIPT] How do I utilise Custom Properties?

Post by Mikk- »

I've been trying to create my own custom properties in ZScript.

What I want is to create a base class for an inventory item with two properties GiveItem and GiveToken. I want to be able to specifiy these two properties in the classes that inherit from the base class. During pickup I want to check for a certain condition and give either the Item or Token speicified in the Default block.

Code: Select all

class w_Pickup : CustomInventory     // This is the base class that all future items will inherit from
    {                                 
    class<inventory> w_Item;          
    class<inventory> w_Token;        
    
    Property GiveItem: w_Item;        // The custom properties, defined as the wiki states (???)
    Property GiveToken: w_Token;    
    
    default
        {
        +COUNTITEM
        +FLOATBOB
        Inventory.PickupFlash "PickupFlash";
        +INVENTORY.FANCYPICKUPSOUND
        Inventory.PickupSound "misc/p_pkup";
        }
    
    
    states
        {
        Pickup:
            TNT1 A 0
                {
                If(CountInv("w_SpellBook1"))
                    { A_GiveInventory(GiveToken); } // I get an unknown identifier error here ... 
                Else
                    { A_GiveInventory(GiveItem); }    // ... and here - despite both being defined. 
                }                                    // Maybe I'm defining them wrong, or accessing them wrong. 
            stop;                                    // Either way it is not particularly clear on the wiki
        }
    }
    
class w_TestToken : w_ItemToken { }

class w_TestItem : ArtiHealth { }

class w_TestPickup : w_Pickup replaces ArtiHealth
    {
    default
        {
        Inventory.PickupMessage "$TXT_ARTIHEALTH";
        w_Pickup.GiveItem("w_TestItem");    
        w_Pickup.GiveToken("w_TestToken");    
        }
    states
        {
        Spawn:
            PTN2 ABC 4;
            Loop;
        }
    } 
in this example if the player picks up w_TestPickup while holding w_SpellBook1 I want the player to recive the item specified in GiveToken. Whereas if they do not currently have the SpellBook item then they receive the GiveItem.

Maybe it's just me, but the wiki seems to be lacking in clarity when it comes to custom properties - sure it tells you how to define them, but to actually use them? no.
Blue Shadow
Posts: 4929
Joined: Sun Nov 14, 2010 12:59 am
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: [ZSCRIPT] How do I utilise Custom Properties?

Post by Blue Shadow »

You don't use the properties, you use the variables when reading and writing.
User avatar
Mikk-
Posts: 2273
Joined: Tue Jun 30, 2009 1:31 pm
Location: Somewhere off Kanagawa

Re: [ZSCRIPT] How do I utilise Custom Properties?

Post by Mikk- »

:oops: Oh! How silly of me. Thanks very much!

Return to “Scripting”