[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!)

[ZSCRIPT] How do I utilise Custom Properties?

Postby Mikk- » Thu Nov 23, 2017 10:32 am

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 allExpand view
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.
User avatar
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922

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

Postby Blue Shadow » Thu Nov 23, 2017 10:42 am

You don't use the properties, you use the variables when reading and writing.
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

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

Postby Mikk- » Thu Nov 23, 2017 10:49 am

:oops: Oh! How silly of me. Thanks very much!
User avatar
Mikk-
yooooooooooo
 
Joined: 30 Jun 2009
Location: Somewhere off Kanagawa
Discord: Mikk0451#3922


Return to Scripting

Who is online

Users browsing this forum: No registered users and 2 guests