Repository navigation
Lua Script API: Event Callbacks
Before getting into it, a bit of context about this. An event is an action or occurrence that signify either a user events, such as pressing buttons or pausing, or a system events, such as spawning notes or the camera moving. When a specific event occurs the corresponding callback will be executed from that event.
Callbacks are special event handler functions that are dealt for specific events design for it. It uses a regular function syntax for its callbacks. Instead of being designed to be stored as data and be execute by another function, from an event listener function. This is were you'll put the designated code for a specific event. Some functions and variables are only have their functionality exclusive to callbacks. For instance updated values for variables and some functions like the getProperty() function.
Note
Some event callbacks have different parameters included in HScript compared to Lua. Some parameters are just added to only HScript and some pre-existing parameters have been removed entirely. If you want to check the list, just click here.
Examples:
function onCreate()
-- starts on create
end
function onUpdate(elapsed)
-- update every frame
endfunction onCreate() {
// starts on create
}
function onUpdate(elapsed:Float) {
// update every frame
}For more information; Main article: Disabling Callbacks
Callbacks have the ability to be disabled completely, this is done by returning Function_Stop variable inside the said callback. This is useful for making your own custom functionality for that callback or disabling the callback altogether. But this is only applied to specific callbacks that have this ability.
Example:
function onGameOver()
return Function_Stop
endFor more information; Main article: Dynamic Callbacks
Dynamic callbacks are only exclusive to HScript or the runHaxeCode() function. It has the ability to override the original functionality by reassigning it with new function content and with the given parameters, if included.
Example:
function onCreatePost() {
game.updateIconsPosition = function() {
game.iconP1.x = 314;
game.iconP2.x = 114;
}
}Triggered when the script has initiated/started, this is only triggered once. This is only used for creating objects, precaching, or setting and getting properties.
Triggered post initiation/start of the script, this is only triggered once. This is only for manipulating its HUD elements, especially for the notes or splash properties.
Triggered when the script has been destroyed, in other words the script has stop executing.
Triggered when the song starts, after the countdown has ended.
Triggered when the song ends, after the song's timer has completed.
Triggered every step, 16 beat per section of the song; this only executes after the countdown. Both the curStep and curDecStep variables must be recommended to be used here, since they were both specifically designed for this purpose.
Triggered every beat, 4 beat per section of the song; this only executes after the countdown. Both the curBeat and curDecBeat variables must be recommended to be used here, since they were both specifically designed for this purpose.
Triggered every 1 beat per section of the song; this only executes after the countdown. The curSection variable must be recommended to be used here, since it was specifically designed for this purpose.
Triggered when the camera moves to focus on a specific character. It could either focus on the player, opponent, or girlfriend.
Example:
function onMoveCamera(focus)
if focus == 'boyfriend' then -- called if the section is a "Must Hit Section"
-- insert code
elseif focus == 'dad' then -- called if the section is NOT a "Must Hit Section"
-- insert code
elseif focus == 'gf' then -- called if the section is a "GF Section"
-- insert her
end
endTriggered every current frame of the game, used for updating values from variables.
-
elapsed- Every current frame display in milliseconds; Shortcut togetPropertyFromClass('flixel.FlxG', 'elapsed').
Triggered after every current frame of the game, used for updating values from variables. This only for manipulating its HUD elements, especially for the notes or splashes properties.
-
elapsed- Every current frame display in milliseconds; Shortcut togetPropertyFromClass('flixel.FlxG', 'elapsed').
Triggered before every score update, from hitting or missing notes. This is only recommended to be used for manipulating the score's current text content either by setting or getting.
-
miss- Whether the player misses or not, returnstrueif missed.
Example:
An example of a custom score text.
local function round(num, decimals)
return math.floor(num * 10^(decimals or 0)) / 10^(decimals or 0)
end
function onCreatePost() -- Initial start
setProperty('scoreTxt.text', 'Taxes: 0 • Ratios: 0 • Knuckles: ?')
end
function onUpdateScore(miss) -- Changes when the score updates
local newScore = 'Taxes: '..score..' • '
local newMiss = 'Ratios: '..misses..' • '
local newAccuracy = 'Knuckles: '..ratingName..' ('..round(rating, 2)..'%)'..' - '..ratingFC
setProperty('scoreTxt.text', newScore..newMiss..newAccuracy)
endTriggered every score update, from hitting or missing notes. This is only recommended to be used for manipulating the score's rating percent, name, and combo names from their derived functions, from: setRatingPercent(), setRatingName(), setRatingFC() functions.
-
miss- Whether the player misses or not, returnstrueif missed.
Example:
Changes the current score's ratings to:
Wario Wah (3.14%) - PP, statically.
function preUpdateScore(miss)
setRatingPercent(math.pi / 100)
setRatingName('Wario Wah')
setRatingFC('PP')
endTriggered before the calculation of the rating data.
Triggered before the countdown has even started, this is only triggered once. This is recommended to be used for playing dialogues, vidoes, and other cutscene related stuff.
Triggered when the countdown has already been started, this is only triggered once. Some stuff has been updated like the note's strumlines will update to their new positions.
Example:
Swaps the player and opponent positions opposite to each-other.
local playerStrumLines = {732, 844, 956, 1068}
local opponentStrumLines = {92, 204, 316, 428}
function onCountdownStarted()
for ind = 0,3 do -- stupid for loop
local newInd = ind + 1 -- because lua uses 1-index for its table
setPropertyFromGroup('playerStrums', ind, 'x', opponentStrumLines[newInd])
setPropertyFromGroup('opponentStrums', ind, 'x', playerStrumLines[newInd])
end
endTriggered in every countdown counter tick until it ended.
-
counter- The current countdown counter tick; Goes from0to4.
Example:
local countdownContent = {'Three', 'Two', 'One', 'Go!', 'The song starts here'}
function onCountdownStarted(counter)
debugPrint('Counter Tick: '..counter..' = '..countdownContent[counter + 1])
--> Counter Tick: 0 = Three
--> Counter Tick: 1 = Two
--> Counter Tick: 2 = One
--> Counter Tick: 3 = Go!
--> Counter Tick: 4 = The song starts here
endTriggered when the next dialogue line starts.
-
dialogueCount- The current dialogue line; Starts at1.
Triggered when skipping a dialogue that was still being typed/loaded.
-
dialogueCount- The current dialogue line; Starts at1.
Note
The parameters for each callback in this section are listed here. Due to stupid, repetitive copy and paste in each callback description. They all work the same as usual in each callback, If you want to know which parameters are included or not, look at each callbacks title, idiot.
-
membersIndex- The current note member ID index. -
noteData- The current direction index of the note; Goes from:0to3, basically left, down, up and right. -
noteType- The current note-type of the note. -
isSustainNote- Whether the notes are sustain (long notes) or not. -
strumTime- The strum time of the notes appearing in game.
Triggered on every note that has currently spawned.
Triggered on each note hit from the player.
Triggered before note hit calculations from the player.
Triggered on each note hit from the opponent.
Triggered before note hit calculations from the opponent.
Triggered on each note miss from the player.
Triggered on each misspress from the player, while no note isn't present. This will be disabled if the "Ghost Tapping" option is enabled.
Note
The parameters for each callback in this section are listed here. Due to stupid, repetitive copy and paste in each callback description. They all work the same as usual in each callback, If you want to know which parameters are included or not, look at each callbacks title, idiot.
-
key- The key associate for each note direction index; Goes from:0to3, basically left, down, up and right.
Triggered if the player presses their own key associate for each note strum.
Triggered before any calculation when the player presses their own key associate for each note strum.
Triggered if the player releases their own key associate for each note strum.
Triggered before any calculation when the player releases their own key associate for each note strum.
Triggered if the player did a ghost tap for each note strum.
Note
The parameters for each callback in this section are listed here. Due to stupid, repetitive copy and paste in each callback description. They all work the same as usual in each callback, If you want to know which parameters are included or not, look at each callbacks title, idiot.
-
eventName- The current event name that was executed currently. -
value1- The current first value inherited by the event. -
value2- The current second value inherited by the event. -
strumTime- The strum time of the notes appearing in game.
Triggered on each event note that is currently executed or from the triggerEvent() function. This is where you'll put each custom event code functionality.
Triggered only once when the game's event note loads; every event note inside the chart. This only used for precaching events that use certain assets like image, sound, etc.
Triggered the event note much more earlier by offsetting it by milliseconds. It must be returning the specified number in milliseconds on each event name.
Example:
The event "Hey!" will be triggered earlier by
1second.
function eventEarlyTrigger(eventName)
if eventName == 'Hey!' then
return 1000
end
endTriggered if the game is currently paused.
Triggered if the game resumed from being paused.
Triggered before the game has started a game-over screen, this is only triggered once. Basically in other words—the health has no health left causing a game-over screen to appear immediately.
Triggered when the game-over screen has been started, this is only triggered once. Some stuff has been updated, the game-over character has been loaded and the game-over music is playing.
Triggered when the player confirmed a retry or exited to the menu.
-
retry- Whether the player confirmed a retry in the game-over screen or not.
Triggered when the timer from the runTimer() function has completed its timer.
-
tag- The current timer tag name that has finished executed currently. -
loops- The current loops that the timer inherited. -
loopsLeft- How many number of loops left does the timer has.
Triggered when the tween from any tween functions has completed its timer.
-
tag- The current tween tag name that has finished executed currently. -
vars- The object of the tag that it inherited.
Triggered when the sound has completed its timer.
-
tag- The current sound tag name that has finished executed currently.
Is the page in some way inaccurate? an error, a typo, or outdated data? To report it, use the "Issue Tab". Or do you wish to include a new function or add new information? use the "Pull Request Tab". Help is always appreciated!
- Event Callbacks
- Custom Sprite
- Custom Text
- Object Functions
- General Functions
- Scripting & File Functions
- Game Input Control Functions
- Language Translation
- HScript Functions
- Custom Substates
- Custom Shaders
- Deprecated & Removed Functions
- Sound & Music Functions
- Tweens & Timers Functions
- Reflection Functions
- Variables