Skip to content

[Suggestion/Proposal] Simple state machine on classes, old UnrealScript like #75

Description

@JSandusky

Simple state machine handling similar to old UnrealScript in classes, best feature of that language. When a state is active its' functions shadow those of the class.

class MyClass {
    void Function() {
        log.Print("default call");
    }

    void GoRed() { SetState(MyClass::RedLight); }

    void GoGreen() { SetState(MyClass::GreenLight); }

    void Reset() { SetState(-1); }

    state RedLight {
        void OnEnter() { // OnEnter / OnExit are optional special titles that will be searched for when the injected 'SetState' function is built
            log.Print("entered red light");
        }
        void Function() {
            log.Print("RED LIGHT!");
        }
    }

    state GreenLight {
        void OnExit() {
            log.Print("left green light");
        }

        void Function() {
            log.Print("GREEN LIGHT");
        }
    }
}

I've got a working implementation of the above with the limitations of no fields/properties in states. Still working out what the awkward cases are.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions