Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Gustavo6046

Members
  • Content count

    1037
  • Joined

  • Last visited

6 Followers

About Gustavo6046

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Single Status Update

See all updates by Gustavo6046

  1. I got to learn ZScript, and it was fun; ZScript is a nice language. I've also learnt to love it! ♥

     

    Below is some example code for YOU to get started!

    /*
     * The code below is toy code for one to learn to use ZScript using examples!
     * It's designed to be a simple introduction for the common DECORATE modder,
     * and with people who don't know a real programming language like C or Java
     * in mind.
     *
     * (C)2017 Gustavo6046. The CC0 license applies.
     */
    
    
    struct Loot // Structs are like folders: they can hold multiple information in a single spot.
    {
        class<Inventory> kind; // A Class is like an actor defined in DECORATE. All monsters in the
                               // level are instances of a Class that has the Monster flag combo.
        
        double chance; // double is a number with decimal point, like 0.4 or 0.8 instead of integers
                       // like 3 or 12.
    }
    
    // Classes now inherit from Object by default.
    // You must define yourself that it inherits from
    // Actor:
    
    class Crate : Actor {
        // An Array is a list that can grow or shrink in size
        // and contain any amount of anything.
        // Better than ACS Arrays, huh?
        Array<Loot> crateLoots;
        
        void addLoot(Loot l) // This is a function. You can call it inside states,
                             // other functions and actions!
        {
            // The next line calls a function on the array
            // crateLoots. The Array's function can be defined
            // as 'void push(Object anything)'.
            crateLoots.push(l);
        }
    }
    
    class CrateOpenOnceOnly : Crate
    {
        bool bOpen; // This is a variable. It is accessible to the instance, so you can just
                    // use it in your statse, functions and actions.
        
        Default // Default is the new block where properties and flags go.
        {
            Scale 1.1;
        }
        
        // "bool" means it returns a boolean value. A_SpawnItemEx for example
        // returns one - whether or not the actor was spawned (true or false).
        action bool A_SpawnCrateLoot()
        {
            if ( crateLoots.size() > 0 )
            { // Use braces to contain multiple statements inside a block statement like an 'if'.
                for ( int i = 0; i < crateLoots.size() ) // For loops! The number I is set to 0, and
                                                         // while it is smaller than the size of the array,
                                                         // it is incremented.
                                        
                    // You can use other actions and functions inside your own action! :D
                    // Using colons you can also give named arguments and skip optional ones.
                    A_SpawnItemEx(crateLoots[i].kind, xvel: FRandom(-8, 8), yvel: FRandom(-8, 8), zvel: FRandom(2, 10));
                    
                    // crateLoots[i] means the (i + 1)th element of the array. I say "+ 1" because indexes begin at
                    // 0 with arrays, not at 1. You might know that from ACS already :)
                    
                return true;
            }
            
            return false;
        }
        
        States // All states end with semicolon (;) now.
        {
            Spawn:
                CRAT A -1; // closed sprite
                Stop;
        
            Open:
                TNT1 A 0 A_JumpIf(bOpen, "AlreadyOpen");
                TNT1 A 0 A_SpawnCrateLoot();
                Goto Opened;
            
            Opened:
                CRAT B -1; // open sprite
                Stop;
                
            AlreadyOpen:
                CRAT CDE 7; // breaking crate sprites
                Stop;
        }
    }

     

×