Skip to content

Commit 633445c

Browse files
authored
Move docs for callbacks above canceling
1 parent a67302e commit 633445c

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

assets/content/cookbook/Advanced/06.ScriptEventCallbacks.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,36 @@ This chapter will walk you through the process of using script event callbacks f
66

77
Several base classes use functions that get an event dispatched to them whenever something in the game happens, such as when getting created or destroyed. With your scripted class, you can override these callbacks to perform custom behavior when these would receive a dispatched event. Not every base class has every callback to their disposal.
88

9+
## Overriding Script Event Callbacks
10+
11+
Even if most base classes have the script event callbacks as empty functions, others have behavior that is entirely dependant on them. As such, you can skip the behavior or call it under a condition depending on if and where you put your super function call. One such example is in the script file for Boyfriend (Christmas)[^bf-christmas]
12+
13+
```haxe
14+
// ...
15+
16+
public override function onNoteHit(event:HitNoteScriptEvent)
17+
{
18+
// ...
19+
20+
// Override the hit note animation.
21+
switch (event.note.kind)
22+
{
23+
case "censor":
24+
holdTimer = 0;
25+
this.playSingAnimation(event.note.noteData.getDirection(), false, 'censor');
26+
return;
27+
case "hey":
28+
holdTimer = 0;
29+
this.playAnimation('hey', true, true);
30+
return;
31+
default:
32+
super.onNoteHit(event);
33+
}
34+
}
35+
36+
// ...
37+
```
38+
939
## Script Event Cancelling
1040

1141
While most cannot be cancelled, cancelling some events provides more leeway to the custom behavior. An example to this would be having pre-song cutscenes, as seen in the script file for the song Darnell[^darnell]
@@ -55,36 +85,6 @@ public override function onNoteMiss(event:NoteScriptEvent):Void
5585
5686
```
5787

58-
## Overriding Script Event Callbacks
59-
60-
Even if most base classes have the script event callbacks as empty functions, others have behavior that is entirely dependant on them. As such, you can skip the behavior or call it under a condition depending on if and where you put your super function call. One such example is in the script file for Boyfriend (Christmas)[^bf-christmas]
61-
62-
```haxe
63-
// ...
64-
65-
function onNoteHit(event:HitNoteScriptEvent)
66-
{
67-
// ...
68-
69-
// Override the hit note animation.
70-
switch (event.note.kind)
71-
{
72-
case "censor":
73-
holdTimer = 0;
74-
this.playSingAnimation(event.note.noteData.getDirection(), false, 'censor');
75-
return;
76-
case "hey":
77-
holdTimer = 0;
78-
this.playAnimation('hey', true, true);
79-
return;
80-
default:
81-
super.onNoteHit(event);
82-
}
83-
}
84-
85-
// ...
86-
```
87-
8888
## List of Script Event Callbacks
8989

9090
There is a predefined list of every script event callback the game has set up to be overridable, with their respective event type whose fields you can read from or write to. More of these will be added to the future.

0 commit comments

Comments
 (0)