Skip to content

Commit 58f20fc

Browse files
anysadKade-github
authored andcommitted
Formatting changes in Script Event Callbacks
Co-Authored-By: anysad <[email protected]>
1 parent f43194a commit 58f20fc

File tree

1 file changed

+114
-61
lines changed

1 file changed

+114
-61
lines changed

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

Lines changed: 114 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,171 +11,223 @@ Several base classes use functions that get an event dispatched to them whenever
1111
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.
1212

1313
- `onScriptEvent(event:ScriptEvent)` - Called when any sort of script event would get dispatched. This is called before the event's respective callback.
14+
1415
- Available to Songs, Stage Props, Boppers, Characters, Stages, Backing Cards, Note Kinds, Dialogue Boxes, Speakers, Conversations and Modules.
1516
- `onCreate(event:ScriptEvent)` - Called when the base class gets created in the game.
17+
1618
- Available to Songs, Stage Props, Boppers, Characters, Stages, Backing Cards, Note Kinds, Dialogue Boxes, Speakers, Conversations and Modules.
1719
- `onDestroy(event:ScriptEvent)` - Called when the base class gets destroyed in the game.
20+
1821
- Available to Songs, Stage Props, Boppers, Characters, Stages, Backing Cards, Note Kinds, Dialogue Boxes, Speakers, Conversations and Modules.
1922
- `onUpdate(event:UpdateScriptEvent)` - Called when the base class gets updated in the game.
23+
2024
- Available to Songs, Stage Props, Boppers, Characters, Stages, Backing Cards, Note Kinds, Dialogue Boxes, Speakers, Conversations and Modules.
2125
- `onStateChangeBegin(event:StateChangeScriptEvent)` - Called when the State changing process begins.
26+
2227
- Available to Backing Cards and Modules.
2328
- `onStateChangeEnd(event:StateChangeScriptEvent)` - Called when the State changing process ends.
29+
2430
- Available to Backing Cards and Modules.
2531
- `onSubStateOpenBegin(event:SubStateScriptEvent)` - Called when the SubState opening process begins.
32+
2633
- Available to Backing Cards and Modules.
2734
- `onSubStateOpenEnd(event:SubStateScriptEvent)` - Called when the SubState opening process ends.
35+
2836
- Available to Backing Cards and Modules.
2937
- `onSubStateCloseBegin(event:SubStateScriptEvent)` - Called when the SubState closing process begins.
38+
3039
- Available to Backing Cards and Modules.
3140
- `onSubStateCloseEnd(event:SubStateScriptEvent)` - Called when the SubState closing process ends.
41+
3242
- Available to Backing Cards and Modules.
3343
- `onFocusLost(event:FocusScriptEvent)` - Called when the focus from the game window is lost.
44+
3445
- Available to Backing Cards and Modules.
3546
- `onFocusGained(event:FocusScriptEvent)` - Called when the focus from the game window is gained.
47+
3648
- Available to Backing Cards and Modules.
3749
- `onAdd(event:ScriptEvent)` - Called when the base class is added to the game stage.
50+
3851
- Available to Stage Props, Boppers and Characters.
3952
- `onNoteIncoming(event:NoteScriptEvent)` - Called when a note is within the field of view.
53+
4054
- Available to Songs, Boppers, Characters, Stages, Notekinds and Modules.
4155
- `onNoteHit(event:HitNoteScriptEvent)` - Called when a note is hit by either character.
56+
4257
- Available to Songs, Boppers, Characters, Stages, Notekinds and Modules.
4358
- `onNoteMiss(event:NoteScriptEvent)` - Called when a note is missed by either character.
59+
4460
- Available to Songs, Boppers, Characters, Stages, Notekinds and Modules.
4561
- `onNoteHoldDrop(event:HoldNoteScriptEvent)` - Called when a hold note is dropped by either character.
62+
4663
- Available to Songs, Boppers, Characters, Stages, Notekinds and Modules.
4764
- `onStepHit(event:SongTimeScriptEvent)` - Called when the Conductor reaches a new step of the music.
65+
4866
- Available to Songs, Boppers, Characters, Stages, Backing Cards and Modules.
4967
- `onBeatHit(event:SongTimeScriptEvent)` - Called when the Conductor reaches a new beat of the music.
68+
5069
- Available to Songs, Boppers, Characters, Stages, Backing Cards and Modules.
5170
- `onPause(event:PauseScriptEvent)` - Called when the main gameplay is paused.
71+
5272
- Available to Songs, Boppers, Characters, Stages and Modules.
5373
- `onResume(event:ScriptEvent)` - Called when the main gameplay is resumed.
74+
5475
- Available to Songs, Boppers, Characters, Stages and Modules.
5576
- `onSongLoaded(event:SongLoadScriptEvent)` - Called when song chart has been parsed but before the notes have been placed, both when starting the song for the first time and retrying the song.
77+
5678
- Available to Songs, Boppers, Characters, Stages and Modules.
5779
- `onSongStart(event:ScriptEvent)` - Called when the song starts.
58-
- Available to Songs, Boppers, Characters, Stages and Modules.
80+
81+
- Available to Songs, Boppers, Characters, Stages and Modules.
5982
- `onSongEnd(event:ScriptEvent)` - Called when the song ends.
60-
- Available to Songs, Boppers, Characters, Stages and Modules.
83+
84+
- Available to Songs, Boppers, Characters, Stages and Modules.
6185
- `onGameOver(event:ScriptEvent)` - Called when the player runs out of health but before the game over substate is opened.
86+
6287
- Available to Songs, Boppers, Characters, Stages and Modules.
6388
- `onSongRetry(event:SongRetryEvent)` - Called when the song retrying process begins, either through the pause menu or through the game over screen.
89+
6490
- Available to Songs, Boppers, Characters, Stages and Modules.
6591
- `onNoteGhostMiss(event:GhostMissNoteScriptEvent)` - Called when the player pressed a key with no notes on the strumline.
92+
6693
- Available to Songs, Boppers, Characters, Stages and Modules.
6794
- `onSongEvent(event:SongEventScriptEvent)` - Called when a song event (such as Focus Camera) is triggered.
95+
6896
- Available to Songs, Boppers, Characters, Stages and Modules.
6997
- `onCountdownStart(event:CountdownScriptEvent)` - Called when the countdown is about to start.
98+
7099
- Available to Songs, Boppers, Characters, Stages and Modules.
71100
- `onCountdownStep(event:CountdownScriptEvent)` - Called when a countdown changes its current step.
101+
72102
- Available to Songs, Boppers, Characters, Stages and Modules.
73-
- `onCountdownEnd(event:CountdownScriptEvent)` - Called when the countdown ends.
103+
- `onCountdownEnd(event:CountdownScriptEvent)` - Called when the countdown ends.
104+
74105
- Available to Songs, Boppers, Characters, Stages and Modules.
75106
- `onDialogueCompleteLine(event:DialogueScriptEvent)` - Called when the player advanced the dialogue while it's being typed.
107+
76108
- Available to Dialogue Boxes, Speakers and Conversations.
77109
- `onDialogueLine(event:DialogueScriptEvent)` - Called when the player advances the dialogue while it's idling.
110+
78111
- Available to Dialogue Boxes, Speakers and Conversations.
79112
- `onDialogueSkip(event:DialogueScriptEvent)` - Called when the dialogue gets skipped.
113+
80114
- Available to Dialogue Boxes, Speakers and Conversations.
81115
- `onDialogueEnd(event:DialogueScriptEvent)` - Called when the dialogue ends.
116+
82117
- Available to Dialogue Boxes, Speakers and Conversations.
83118

84119
## List of Event Types
85120

86121
There is a predefined list of script events, whose fields are readable and, in some cases, changeable, that get dispatched to script event callbacks. More of these will be added in the future. See above which callback accepts which event.
87122

88123
- `ScriptEvent`, with fields:
89-
- (read-only) `cancelable` - If the event can be canceled.
90-
- (read-only) `type` - The type of the event.
91-
- (read-only) `shouldPropagate` - If the event can be dispatched to its respective callback. If false, it will only get dispatched to `onScriptEvent`.
92-
- (read-only) `eventCanceled` - If the event has been cancelled.
93-
- `cancelEvent()` - Cancels the event, if possible.
94-
- `cancel()` - Cancels the event, if possible.
95-
- `stopPropagation()` - Stops the propagation of this event.
124+
125+
126+
- (read-only) `cancelable` - If the event can be canceled.
127+
- (read-only) `type` - The type of the event.
128+
- (read-only) `shouldPropagate` - If the event can be dispatched to its respective callback. If false, it will only get dispatched to `onScriptEvent`.
129+
- (read-only) `eventCanceled` - If the event has been cancelled.
130+
- `cancelEvent()` - Cancels the event, if possible.
131+
- `cancel()` - Cancels the event, if possible.
132+
- `stopPropagation()` - Stops the propagation of this event.
96133

97134
- `UpdateScriptEvent`, with fields:
98-
- Inherited from `ScriptEvent`.
99-
- (read-only) `elapsed` - How much time has passed since the last update.
135+
136+
- Inherited from `ScriptEvent`.
137+
- (read-only) `elapsed` - How much time has passed since the last update.
100138

101139
- `StateChangeScriptEvent`, with fields:
102-
- Inherited from `ScriptEvent`.
103-
- (read-only) `targetState` - The State that was switched to.
140+
141+
- Inherited from `ScriptEvent`.
142+
- (read-only) `targetState` - The State that was switched to.
104143

105144
- `SubStateScriptEvent`, with fields:
106-
- Inherited from `ScriptEvent`.
107-
- (read-only) `targetState` - The SubState that was opened/closed.
145+
146+
- Inherited from `ScriptEvent`.
147+
- (read-only) `targetState` - The SubState that was opened/closed.
108148

109149
- `FocusScriptEvent`, with fields:
110-
- Inherited from `ScriptEvent`.
150+
151+
- Inherited from `ScriptEvent`.
111152

112153
- `NoteScriptEvent`, with fields:
113-
- Inherited from `ScriptEvent.`
114-
- (read-only) `note` - The NoteSprite associated with this event.
115-
- (read-only) `comboCount` - The currently ongoing combo.
116-
- `playSound` - Whether to play a miss sound when missing a note.
117-
- `healthChange` - The amount of health to add to the player. Can be a negative value too.
154+
155+
- Inherited from `ScriptEvent.`
156+
- (read-only) `note` - The NoteSprite associated with this event.
157+
- (read-only) `comboCount` - The currently ongoing combo.
158+
- `playSound` - Whether to play a miss sound when missing a note.
159+
- `healthChange` - The amount of health to add to the player. Can be a negative value too.
118160

119161
- `HitNoteScriptEvent`, with fields:
120-
- Inherited from `NoteScriptEvent`.
121-
- `judgement` - The judgement received from hitting the note.
122-
- `score` - The score received from hitting the note.
123-
- `isComboBreak` - If the hit caused a combo break.
124-
- `hitDiff` - The time difference (in miliseconds) when the player hit the note.
125-
- `doesNotesplash` - If the note does a splash, defaults to true when the judgement is "sick".
162+
163+
- Inherited from `NoteScriptEvent`.
164+
- `judgement` - The judgement received from hitting the note.
165+
- `score` - The score received from hitting the note.
166+
- `isComboBreak` - If the hit caused a combo break.
167+
- `hitDiff` - The time difference (in miliseconds) when the player hit the note.
168+
- `doesNotesplash` - If the note does a splash, defaults to true when the judgement is "sick".
126169

127170
- `HoldNoteScriptEvent`, with fields:
128-
- Inherited from `NoteScriptEvent`.
129-
- `holdNote` - The SustainTrail object associated with this event.
130-
- `score` - The score received from hitting the note.
131-
- `isComboBreak` - If the hit caused a combo break.
132-
- `hitDiff` - The time difference (in miliseconds) when the player hit the note.
133-
- `doesNotesplash` - If the note does a splash, defaults to true when the judgement is "sick".
171+
172+
- Inherited from `NoteScriptEvent`.
173+
- `holdNote` - The SustainTrail object associated with this event.
174+
- `score` - The score received from hitting the note.
175+
- `isComboBreak` - If the hit caused a combo break.
176+
- `hitDiff` - The time difference (in miliseconds) when the player hit the note.
177+
- `doesNotesplash` - If the note does a splash, defaults to true when the judgement is "sick".
134178

135179
- `SongTimeScriptEvent`, with fields:
136-
- Inherited from `ScriptEvent`.
137-
- (read-only) `beat` - The current beat of the song.
138-
- (read-only) `step` - The current step of the song.
180+
181+
- Inherited from `ScriptEvent`.
182+
- (read-only) `beat` - The current beat of the song.
183+
- (read-only) `step` - The current step of the song.
139184

140185
- `PauseScriptEvent`, with fields:
141-
- Inherited from `ScriptEvent`.
142-
- `gitaroo` - If the Gitaroo Man easter egg should be used.
186+
187+
- Inherited from `ScriptEvent`.
188+
- `gitaroo` - If the Gitaroo Man easter egg should be used.
143189

144190
- `SongLoadScriptEvent`, with fields:
145-
- Inherited from `ScriptEvent`.
146-
- (read-only) `id` - The song id associated with the event.
147-
- (read-only) `difficulty` - The song difficulty associated with the event.
148-
- `notes` - An Array of SongNoteData objects representing the notes for the chart.
149-
- `events` - An Array of SongEventData objects representing the events for the chart.
191+
192+
- Inherited from `ScriptEvent`.
193+
- (read-only) `id` - The song id associated with the event.
194+
- (read-only) `difficulty` - The song difficulty associated with the event.
195+
- `notes` - An Array of SongNoteData objects representing the notes for the chart.
196+
- `events` - An Array of SongEventData objects representing the events for the chart.
150197

151198
- `SongRetryEvent`, with fields:
152-
- Inherited from `ScriptEvent`.
153-
- (read-only) `difficulty` - The new difficulty of the song.
199+
200+
- Inherited from `ScriptEvent`.
201+
- (read-only) `difficulty` - The new difficulty of the song.
154202

155203
- `GhostMissNoteScriptEvent`, with fields:
156-
- Inherited from `ScriptEvent`.
157-
- (read-only) `dir` - The direction (1-4) that was mistakenly pressed.
158-
- (read-only) `hasPossibleNotes` - If there were notes within judgement range when the key was pressed.
159-
- `healthChange` - The amount of health to add to the player. Can be a negative value too.
160-
- `scoreChange` - The amount of score to add to the player. Can be a negative value too.
161-
- `playSound` - Whether to play a miss sound.
162-
- `playAnim` - Whether to play a miss animation.
204+
205+
- Inherited from `ScriptEvent`.
206+
- (read-only) `dir` - The direction (1-4) that was mistakenly pressed.
207+
- (read-only) `hasPossibleNotes` - If there were notes within judgement range when the key was pressed.
208+
- `healthChange` - The amount of health to add to the player. Can be a negative value too.
209+
- `scoreChange` - The amount of score to add to the player. Can be a negative value too.
210+
- `playSound` - Whether to play a miss sound.
211+
- `playAnim` - Whether to play a miss animation.
163212

164213
- `SongEventScriptEvent`, with fields:
165-
- Inherited from `ScriptEvent`.
166-
- (read-only) `eventData` - The SongEventData object associated with the event.
214+
215+
- Inherited from `ScriptEvent`.
216+
- (read-only) `eventData` - The SongEventData object associated with the event.
167217

168218
- `CountdownScriptEvent`, with fields:
169-
- Inherited from `ScriptEvent`.
170-
- (read-only) `step` - The current countdown step. Can be *BEFORE*, *THREE*, *TWO*, *ONE*, *GO* or *AFTER*.
219+
220+
- Inherited from `ScriptEvent`.
221+
- (read-only) `step` - The current countdown step. Can be `BEFORE`, `THREE`, `TWO`, `ONE`, `GO` or `AFTER`.
171222

172223
- `DialogueScriptEvent`, with fields:
173-
- Inherited from `ScriptEvent`.
174-
- (read-only) `conversation` - The Conversation object associated with the event.
224+
225+
- Inherited from `ScriptEvent`.
226+
- (read-only) `conversation` - The Conversation object associated with the event.
175227

176228
## Script Event Cancelling
177229

178-
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]:
230+
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]
179231
```haxe
180232
// ...
181233
@@ -207,7 +259,7 @@ public override function onCountdownStart(event:CountdownScriptEvent):Void
207259

208260
## Overriding Script Event Callbacks
209261

210-
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]:
262+
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]
211263
```haxe
212264
// ...
213265
@@ -234,6 +286,7 @@ function onNoteHit(event:HitNoteScriptEvent)
234286
235287
// ...
236288
```
289+
237290
[^darnell]: <https://github.com/FunkinCrew/funkin.assets/blob/main/preload/scripts/songs/darnell.hxc>
238291
[^bf-christmas]: <https://github.com/FunkinCrew/funkin.assets/blob/main/preload/scripts/characters/bf-christmas.hxc>
239292

0 commit comments

Comments
 (0)