3
Scripting
entar edited this page 2025-08-11 15:31:05 +07:00

Here i will define all the functions, arguments and shared variables module / chart / stage scripts can use.

Script Functions

  • module.onCreate(songName) -- That function is called whenever the PlayState launches, even before the game fully loads. At this point you usually create the stage background.
  • module.onUpdate(deltaTime, elapsed) -- Calls before every frame render, here you usually update your sprites depending on the condition / song time. Delta stands for the last frame render time and elapsed stands for the current song time.
  • module.onClose() -- Gets called when the PlayState is exiting / Player dies. Here you remove all calculations / other stuff (Sprites are cleaned up automatically)
  • module.onBeat(beat) -- Gets called every beat. Obvious.
  • module.noteHit(note) -- Gets called when the PLAYER hits a note (or a sustain fragment).
  • module.opponentNoteHit(note) -- Gets called when the OPPONENT hits a note (or a sustain fragment).
  • module.processNote(note) -- This function is called whenever a note is getting created. This is used for custom note stuff.
  • module.onPause() -- Gets called when the player pauses the game.
  • module.onUnpause() -- Gets called when the player unpauses the game.
  • module.onDeath() -- Gets called when the player loses.
  • module.drawBelowUI() -- This function is used to draw stuff below UI (love.graphics.draw etc.) (Draws on the GAME canvas.).
  • module.onDraw() -- This function is used to draw stuff above UI (love.graphics.draw etc.) (Draws on the UI canvas.).
  • module.onEvent(event) -- Gets called when a event gets ran.

Shared variables.

Shared variables are accessible through module.shared

sharedVars.canStart = boolean -- Tells the game if it can start. Should only change at the onCreate() function and then resuming it through another function like onUpdate() check.
sharedVars.shouldCountdown = boolean -- Will the game countdown or not (used for pre-game cutscenes etc.) Should only change at the onCreate() function and then resuming it through another function like onUpdate() check.
sharedVars.screenSize = Vector2 -- Only usable in module.onCreate()
sharedVars.canvasSize = Vector2 -- Only usable in module.onCreate()
sharedVars.settings = table -- Parsed settings.json file
sharedVars.receptors = table -- List of receptor sprites
sharedVars.opponentReceptors = table -- List of opponent's receptor sprites
sharedVars.health = number -- Player health. 0-2
sharedVars.speed = number -- Chart speed. Can not be 0
sharedVars.ui = {
    healthIcons = true, -- If health is false it wont render either way
    health = true
    score = true,
} -- List of UI toggles
sharedVars.zoom = number -- Game zoom.
sharedVars.notes = table -- List of notes.
sharedVars.holds = table -- List of sustain notes.
sharedVars.characters = {
    dad = character,
    bf = character,
    gf = character
} -- List of characters

For what you can do with notes and characters look at Notes and Characters

Overall type manupulation for scripts