Init Functions - polytrackmods/PolyModLoader GitHub Wiki

Why init() functions?

Ideally, none of your code actually runs on its own, it's either ran by the mod loader when your mod loads or by the game itself through mixins.

The different functions

Currently, there are three init functions:

  • init(pml): The regular init, gets called with an instance of PolyModLoader (pml) after everything in PolyTrack gets declared, but before anything runs.
  • postInit(): Gets called right after the game finishes loading, right before the main menu gets shown.
  • simInit(): DOES NOT GET CALLED IN SIM WORKER. This gets called right after the worker gets crated and right before simulation mixins are sent over. This is the 'last call' for you to register simulation mixins.

Please keep in mind that any function call that stats with pml. in any other page assumes that your init is declared with the argument called pml like in the example above. In simple terms, pml is the instance of PolyModLoader.

Adding them to your mod

If you're coming straight from the quick start, your mod class looks like this:

class YourMod extends PolyMod {

}

Every init function goes inside your mod class, and has to be declared using lambdas.

class YourMod extends PolyMod {
    init = (pml) => {
        this.pml = pml; // so pml is accessible outside of init (not neccesary)
        // regular init
    }
    postInit = () => {
        // post init
    }
    simInit = () => {
        // sim init here
    } 
}

It is recommended to add any useful function you add into your mod's class so other mods can use them as well.