Skip to content

Commit 01a3a8b

Browse files
Custom Classes Docs + other HScript features docs (#155)
1 parent 67f2f90 commit 01a3a8b

8 files changed

Lines changed: 192 additions & 46 deletions

File tree

wiki/modding/scripting/custom-classes.md

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
author: Ne_Eo, Frakits & Jamextreme140
3+
desc: This page explains how to create custom classes for your mod!
4+
lastUpdated: 2025-09-19T04:13:02.526Z
5+
title: Custom Classes
6+
---
7+
# Custom Classes
8+
9+
Custom classes can be made either inside the script you need it in or you can make a script file corresponding with the name of the class in ``./source``, and using <syntax lang="haxe">import</syntax> to import it.
10+
11+
Here is a basic Song Script code that uses it:
12+
```haxe
13+
package; // Allow `package` declaration. Ignored by the interpreter.
14+
15+
class SpecialSprite extends FlxSprite {
16+
public static function getSprite(v:String) {
17+
return new SpecialSprite(v);
18+
}
19+
20+
public var customValue(default, set):String = null;
21+
private function set_customValue(v:String):String {
22+
if(v == "powerful")
23+
trace("I'm powerful!");
24+
loadGraphic(Paths.image(v));
25+
return customValue = v;
26+
}
27+
28+
public function new(customValue:String) {
29+
super(200, 400, null);
30+
this.customValue = customValue;
31+
//other code stuff
32+
}
33+
34+
public override function update(elapsed) {
35+
super.update(elapsed);
36+
}
37+
}
38+
39+
function create() {
40+
var spr = SpecialSprite.getSprite("powerful");
41+
add(spr);
42+
}
43+
```
44+
45+
## Particularities
46+
As of writing this, this system is limited and also presents some defects. For example:
47+
- You cannot extend FlxGroups or other typed classes *(the ones that end with a ``<T>``)*. This will be implemented in the future.
48+
- Compiled Classes that do not override a function in their code cannot have that function overridden by custom classes. For example, you can't override the `draw` method in a custom class that extends <syntax lang="haxe">FlxParticle</syntax>, because <syntax lang="haxe">FlxParticle</syntax> does not override `draw`. This will be fixed in the future.
49+
- private variables and functions has not effect. They can be accessed as public variables.
50+
- You can only extend a class that is in the packages, `flixel`, `funkin` and `modchart`.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
author: Jamextreme140
3+
desc: This page explains how to use scripted enums for your mod!
4+
lastUpdated: 2025-09-12T08:53:13.034Z
5+
title: Enums
6+
---
7+
# Enums
8+
9+
Enums are a good choice if only a finite set of values should be allowed. It can be made inside the script you need it in.
10+
11+
Here is a basic Enum Script example:
12+
13+
```haxe
14+
enum TypeValue {
15+
NUMBER(n:Int);
16+
DECIMAL(d:Float, ?p:Int);
17+
CHARACTER(s:String);
18+
BOOLEAN(b:Bool);
19+
}
20+
21+
var type:TypeValue;
22+
23+
function create() {
24+
type = TypeValue.DECIMAL(10.1234, 2);
25+
26+
// You need to type the full enum field for each case
27+
// i.e. you can't type the enum field directly (limitation for now)
28+
switch(type) {
29+
case TypeValue.NUMBER(number):
30+
trace("number: " + number);
31+
case TypeValue.DECIMAL(decimal, precision):
32+
if(precision != null)
33+
trace("decimal: " + decimal + " | rounded decimal: " + roundDecimal(decimal, precision));
34+
else
35+
trace("decimal: " + decimal);
36+
case TypeValue.CHARACTER(char):
37+
trace("character: " + char);
38+
default:
39+
trace("unknown type");
40+
}
41+
}
42+
43+
44+
function roundDecimal(Value:Float, Precision:Int) {
45+
var mult:Float = Math.pow(10, Precision);
46+
return Math.fround(Value * mult) / mult;
47+
}
48+
```
49+
50+
Supports Enum matching with arguments for switch statements (for real and scripted enums).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
author: Jamextreme140
3+
desc: This page explains how to use the following scripting features in your mod!
4+
lastUpdated: 2025-09-19T04:11:01.175Z
5+
title: Scripting Features
6+
---
7+
# Scripting Features
8+
9+
- [Custom Classes](./custom-classes.md)
10+
- [Enums](./enums.md)
11+
- [Property Fields](./property-fields.md)
12+
- [Static Extension](./static-extension.md)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
author: Jamextreme140
3+
desc: This page explains how to use property fields for your mod!
4+
lastUpdated: 2025-09-12T09:49:51.453Z
5+
title: Property Fields
6+
---
7+
# Property Fields (get/set variables)
8+
9+
Property Fields provide a way to control access to script or class fields, offering more flexibility than simple variables. They are defined by specifying read and write access identifiers within parentheses after the field name.
10+
11+
Here is a basic Property Field usage example:
12+
13+
`./songs/script1.hx`
14+
15+
```haxe
16+
public var myvar(default, set):Int;
17+
18+
function set_myvar(val:Int):Int {
19+
if(val > 10) return myvar = val;
20+
return val;
21+
}
22+
```
23+
24+
`./songs/[SONG NAME]/scripts/script2.hx`
25+
26+
```haxe
27+
function create() {
28+
myvar = 20; // This will trigger the set call stored on the field.
29+
}
30+
```
31+
32+
More information about property fields [here](https://haxe.org/manual/class-field-property.html).
33+
34+
## Particularities
35+
As of writing this, this system presents some limitations. For example:
36+
- `(get, null)` or `(null, set)` has no effect for writing nor reading, it acts like (get, default).
37+
- Calling the get/set function directly will trigger that function twice due to accessing the property field on call (if is a real variable, like `(get, null)` or `(default, set)`). For example, calling directly `set_myvar` will call the same function again when tries to write on `myvar`. Avoid doing this unless you have a full property field (a non-real variable, i.e. `(get, set)` or `(get, never)`). This will be fixed in the future.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
author: Jamextreme140
3+
desc: This page explains how to use static extension for your mod!
4+
lastUpdated: 2025-09-12T09:50:05.405Z
5+
title: Static Extension
6+
---
7+
# Static Extension
8+
9+
Static extensions provide a mechanism to "extend" existing types with new functionality without modifying their original source code. This can be used either with real and custom classes.
10+
11+
Here is a basic Static Extension example:
12+
13+
```haxe
14+
using StringTools;
15+
16+
class IntExtender {
17+
static public function triple(i:Int) {
18+
return i * 3;
19+
}
20+
}
21+
22+
// need to create/import the custom class
23+
// before setting the extension (limitation for now)
24+
using IntExtender;
25+
26+
var str = " Hello World! ";
27+
28+
function create() {
29+
trace(str.trim()); // "Hello World!"
30+
trace(12.triple()); // 36
31+
}
32+
33+
```
34+
35+
More information about static extension [here](https://haxe.org/manual/lf-static-extension.html).

wiki/modding/scripting/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
author: Frakits
33
desc: This page explains how to script the engine
4-
lastUpdated: 2025-01-08T23:47:04.206Z
4+
lastUpdated: 2025-09-12T09:36:28.820Z
55
title: Scripting
66
---
77
# Scripting
@@ -76,6 +76,7 @@ We have a special variable named `__script__` that points to the script that is
7676
- <a href="./script-calls.md">All of the script calls</a>
7777

7878
And if you wanna go advanced, follow the rest of the articles here:
79+
- <a href="./features/index.md">Scripting Features</a>
7980
- <a href="./playstate-scripts/pause-gameover-scripts.md">Pause/Game Over Scripts</a>
8081
- <a href="./playstate-scripts/cutscenes-dialogue-scripts.md">Cutscenes/Dialogue Scripts</a>
8182
- <a href="./playstate-scripts/character-stage-scripts.md">Character/Stage Scripts</a><br><br>
@@ -85,6 +86,5 @@ And if you wanna go advanced, follow the rest of the articles here:
8586
- <a href="./3d-rendering.md">3D rendering</a>
8687
- <a href="./hxvlc.md">Using hxvlc for videos</a><br><br>
8788
- <a href="./scripted-assets-libraries.md">Scripted Assets Libraries</a>
88-
- <a href="./custom-classes.md">Custom Classes</a>
8989
- <a href="./ndll-scripting.md">NDLL Scripting</a>
9090
- <a href="./custom-transitions.md">Custom Transitions</a>

wiki/wiki.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
["cutscenes-dialogues", "Cutscenes/Dialogues"],
2424
["note-splashes", "Note Splashes"],
2525
["scripting/index", "Scripting", [
26+
["features/index", "Features", [
27+
["custom-classes", "Custom Classes"],
28+
["enums", "Enums"],
29+
["property-fields", "Property Fields"],
30+
["static-extension", "Static Extension"]
31+
]],
2632
["playstate-scripts/index", "PlayState Scripts", [
2733
["gameplay-scripts", "Gameplay Scripts"],
2834
["events-notetypes-scripts", "Events/Notetype Scripts"],
@@ -36,7 +42,6 @@
3642
["hxvlc", "Using hxvlc for videos"],
3743
["custom-options", "Custom Options"],
3844
["custom-controls", "Custom Controls"],
39-
["custom-classes", "Custom Classes"],
4045
["3d-rendering", "3D rendering - UNFINISHED"],
4146
["script-calls", "All of the script calls - UNFINISHED"],
4247
["script-snippets", "Useful script snippets for modders - UNFINISHED"],

0 commit comments

Comments
 (0)