Codename Logo Codename Logo

State/Substate Scripts

APIWiki

State/Substate Scripts

State/Substate Scripts are scripts that can change any state or substate of the game.
You can change the Main Menu, the Freeplay Menu and even the Chart Editor.

Modifying a pre-existing State/Substate

To get started, make a Script in ./data/states and name it corresponding to the state/substate you want to change.

For example, if you decide to change the Main Menu, make a Script like this ./data/states/MainMenuState.hx
A basic Main Menu modification looks like this:

function postCreate() {
    forceCenterX = false; // disable the code that centers the menu buttons.
    for (i=>button in menuItems.members) {
        button.x += Math.sin(i) * 300; // move buttons
    }
}

This code results in the menu looking like this.

You can do this with every State/Substate of course, but keep in mind you have to study the state's code first before modifying it. (you can find the code in Codename Engine's Repository)
Also look for All of the script calls for menu script calls

Creating custom States/Substates

You can also create entirely custom ones too! By putting them in the same ./data/states/ folder, you create new ModStates/ModSubstates.

Accessing them is done via this piece of code:

FlxG.switchState(new ModState("MyCustomState")); // assuming we have made a new Script ./data/states/MyCustomState.hx

or this code

openSubstate(new ModSubState("MyCustomSubstate")) // assuming we have made a new Script ./data/states/MyCustomSubstate.hx
Written by: Frakits
Last updated: 2024-09-05