Codename Logo Codename Logo

Custom Options

APIWiki

Custom Options

You may find it useful to have custom options specific to your mod, thankfully you can do just that!

To get started, put a file in ./data/config called options.xml.

There already exists a template for you to look on, and it looks something like this:

<menu name="Mod Options" desc="Modify mod options here">

    <checkbox id="checkboxExample" name="Checkbox example" />

    <number id="numberExample" name="Number example" min="0" max="10" change="1"/>

    <choice id="choiceExample" name="Choice Example">
        <value name="Disabled" value="disabled"/>
        <value name="This only" value="thisOnly"/>
        <value name="All" value="all"/>
    </choice>

    <menu name="Submenu Example" desc="Submenu test">
        <checkbox id="levelOfIdk2" name="Level of idk" />
    </menu>

</menu>

You're likely wondering: "how does each type of option work?" That's what is about to be explained!!

All option types (except for <menu>) share 2 common properties:

Here's what the properties for each type are:

Accessing them in Scripts is done via FlxG.save.data, as you can see below.

var checkboxExample = FlxG.save.data.checkboxExample;

You may have noticed that none of the option types have a default value property, this is because you have to set the default values yourself (in a global script).
You have to do this otherwise your options won't save correctly!

This is rather easy to do, put this in ./data/global.hx:

function new() {
    // FlxG.save is your mod's save data
    if(FlxG.save.data.checkboxExample == null)
        FlxG.save.data.checkboxExample = true;

    // You can also do
    // FlxG.save.data.checkboxExample ??= true;
}
Written by: Frakits & Swordcube
Last updated: 2024-09-11