SurgeScript

Created on 2023-08-27T23:21:48-05:00

Return to the Index

This card pertains to a resource available on the internet.

This card can also be read via Gemini.

C#-esque syntax.

Tags, state machines, and ownership heirarchy are stored as part of a game object and get some special syntax considerations.

There is no inheritance of objects as in C-langs. Objects may hold child objects, have tags, and some of those child objects may have interesting behavior within their state machines. You are encouraged to implement behavior as objects and then attach them to a parent object, something called an "entity component system."

Tags

Each object has an array of tags attached to it when created. You can check those.

object "Horse" is "animal", "vehicle"
{
    state "main"
    {
    }
}

object "Application"
{
    horse = spawn("Horse");
    state "main"
    {
        // Horse is both an animal and a vehicle
        Console.print(horse.hasTag("animal")); // true
        Console.print(horse.hasTag("vehicle")); // true
    }
}

State machines

State machines are syntax sugar for an integer, timestamp, and switch statement which is run every frame (the "think" method on objects.)

object "Cosmic Door"
{
    state "main"
    {
        // the object starts at the main state
        state = "opened"; // go to the opened state
    }

    state "opened"
    {
        if(timeout(2)) // if we have been on the opened state for 2+ seconds
            state = "closed"; // go to the closed state
    }

    state "closed"
    {
        if(timeout(2))
            state = "opened";
    }
}