Friday Night Funkin' Cookbook
Friday Night Funkin' CookbookExpertMiscellaneous Coding Tricks

Miscellaneous Coding Tricks

Reading time: 1.5 minute

This article will cover a handful of miscellaneous coding tricks that you could do in the game, largely thanks to the framework Funkin' was built on - HaxeFlixel.

Most of these are recommeded to be used with Modules, so it is recommended that you familiarize yourself with them beforehand.

Accessing the game's traces

By opening the command prompt and navigating to the folder the Funkin' application is with the cd path/to/move/to command, you can run ./Funkin on Windows and Linux to open the game on the console.

noteNote

On macOS, you need to find where the Funkin.app file is before right-clicking it and selecting "Open File Content". Afterwards, you need to navigate to the "Contents/MacOS" to find the Funkin' executable. Double-clicking it will open the terminal, containing every trace on the console.

This has the benefits of being able to see what the game prints on the console, which is useful for debugging. On top of that, you can even print on the console yourself by using the trace() function, like in the following example.

// ...

public override function onCreate(event:ScriptEvent)
{
    super.onCreate(event);

    trace("Created!");
}

// ...

The traces, both by the source code and by the scripts, redirect to the file it was traced from. To separate the two, traces done by scripts are made distinct by encompassing the path in hscriptClass().

Activating something only on game launch

As of 0.8.0, the onCreate function on Modules gets dispatched on hot-reloading, alongside getting dispatched after everything in the game was initialized. This could potentially break a couple of things that the programmer wanted to only be activated once, on game launch. Luckily, Flixel provides a signal for this - FlxG.signals.postGameStart, which gets dispatched after everything in the game's initialization state gets created.

You could use it as follows:

import flixel.FlxG;
import funkin.modding.module.Module;

// ...

class IntroModule extends Module
{
    var isInIntro:Bool = false;

    public override function new()
    {
        super("IntroModule", 0);

        // add a signal that only gets dispatched in the once in a play session
        FlxG.signals.postGameStart.addOnce(function()
        {
            isInIntro = true;
        });
    }

    public override function onCreate(event:ScriptEvent)
    {
        if (isInIntro)
        {
            // add some code here
        }
    }
}

Contributors:
Kolo
Last modified:
Created:
Category:  Expert
Tags: