Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions assets/content/cookbook/Expert/-06.MiscellaneousCodingTricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@ This article will cover a handful of miscellaneous coding tricks that you could

Most of these are recommeded to be used with [Modules](01.ScriptedModules.md), 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.

> [!NOTE]
> 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.

```haxe
// ...

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.
Expand Down