Skip to content

Commit e43398f

Browse files
KoloInDaCribKade-github
authored andcommitted
article about epic coding tricks!!! for gamers only
1 parent c79def3 commit e43398f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[tags]: / "expert,hscript"
2+
3+
# Miscellaneous Coding Tricks
4+
5+
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.
6+
7+
Most of these are recommeded to be used with [Modules](01.ScriptedModules.md), so it is recommended that you familiarize yourself with them beforehand.
8+
9+
## Activating something only on game launch
10+
11+
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.
12+
13+
You could use it as follows:
14+
15+
```haxe
16+
import flixel.FlxG;
17+
import funkin.modding.module.Module;
18+
19+
// ...
20+
21+
class IntroModule extends Module
22+
{
23+
var isInIntro:Bool = false;
24+
25+
public override function new()
26+
{
27+
super("IntroModule", 0);
28+
29+
// add a signal that only gets dispatched in the once in a play session
30+
FlxG.signals.postGameStart.addOnce(function()
31+
{
32+
isInIntro = true;
33+
});
34+
}
35+
36+
public override function onCreate(event:ScriptEvent)
37+
{
38+
if (isInIntro)
39+
{
40+
// add some code here
41+
}
42+
}
43+
}
44+
45+
```
46+
47+
> Author: [KoloInDaCrib](https://github.com/KoloInDaCrib)

0 commit comments

Comments
 (0)