Psych Engine Logo
T-Bar Engine - Documentation

List of Playstate callbacks

  • onCreate()

    - Called when the script is first created.

  • onCreatePost()

    - Called at the end of "create".

  • onUpdate(elapsed:Float)

    - Called every frame. "elapsed" will always equal to 1, no matter the FPS.

  • onUpdatePost(elapsed:Float)

    - Called at the end of "update". "elapsed" will always equal to 1, no matter the FPS.

  • onDestroy()

    - Called when the script is destroyed.

  • onStepHit()

    - Called 16 times per section.

  • onBeatHit()

    - Called 4 times per section.

  • onSectionHit()

    - Called every section.

  • onStartCountdown()

    - Called when the countdown starts. Return "Function_Stop" to prevent the countdown from starting.

  • onCountdownStarted()

    - Called AFTER the countdown started.

  • onSongStart()

    - Called when the song itself starts.

  • onSongEnd()

    - Called when the song ends. Return "Function_Stop" to prevent the song from ending.

  • onPause()

    - Called when the pause menu is opened. Return "Function_Stop" to prevent the player from pausing.

  • onResume()

    - Called when the song is resumed from the pause menu.

  • onGameOver()

    - Called when you get a game over. Return "Function_Stop" to prevent yourself from going to the game over screen.

  • onGameOverConfirm(retry:Bool)

    - Called when an option is selected in the game over. If you chose to restart the song, "retry" will be true.

  • onNextDialogue(line:Int)

    - Called when the next dialogue line starts. The Dialogue line starts with 1.

  • onSkipDialogue(line:Int)

    - Called when you skip a dialogue line that was still being typed. The Dialogue line starts with 1.

  • onKeyPressPre(key:Int)

    - Called before the calculations for a note key pressed is made. "key" can be 0 (left), 1 (down), 2 (up), or 3 (right). Return "Function_Stop" to stop the calculations.

  • onKeyPress(key:Int)

    - Called when a note key is pressed. "key" can be 0 (left), 1 (down), 2 (up), or 3 (right).

  • onKeyReleasePre(key:Int)

    - Called before the calculations for a note key released is made. "key" can be 0 (left), 1 (down), 2 (up), or 3 (right). Return "Function_Stop" to stop the calculations.

  • onKeyRelease(key:Int)

    - Called when a note key is released. "key" can be 0 (left), 1 (down), 2 (up), or 3 (right).

  • onGhostTap(key:Int)

    - Called when a note key is pressed, but there are no notes to be pressed. "key" can be 0 (left), 1 (down), 2 (up), or 3 (right).

  • noteMissPress(direction:Int)

    - Called after the miss calculations when a note key is pressed, but there are no notes to be pressed. "direction" can be 0 (left), 1 (down), 2 (up), or 3 (right).

  • onRecalculateRating()

    - Called when the game recalculates the song rating. Return "Function_Stop" to prevent the game from recalculating (Could be used for your own calculations).

    Note: onRecalculateRating is called BEFORE the calculations begin.

  • preUpdateScore(miss:Bool)

    - Called before the game updates the song score and score text. Return "Function_Stop" to prevent the game from recalculating (Could be used for your own calculations).

    Note: preUpdateScore is called BEFORE the calculations begin.

  • onUpdateScore(miss:Bool)

    - Called when the game updates the song score and score text.

  • onMoveCamera(focus:String)

    - Called when the camera focuses on a character. "focus" can either be "boyfriend" or "dad".

  • onEvent(name:String, value1:String, value2:String, strumTime:Float)

    - Called when an event named "name" is triggered, with "value1" and "value2" being the inputted values in the event triggered.

  • onEventPushed(name:String, value1:String, value2:String, strumTime:Float)

    - Called when an event is first created and pushed to the chart data. This is recommened for precaching assets if your event uses those.

  • eventEarlyTrigger(name:String)

    - If returned with a numerical value, it will play the event with "name" the returned value (in milliseconds) before the actual event trigger (Example: doing `if(name == "custom event") return 280;` will make the event named "custom event" call 280 milliseconds before the actual event trigger).

  • onCustomSubstateCreate(name:String)

    - Called when your custom substate is created, with "name" being the... name... defined in "openCustomSubstate(name)".

  • onCustomSubstateCreatePost(name:String)

    - Called after your custom substate is created.

  • onCustomSubstateUpdate(name:String, elapsed:Float)

    - Called every frame that your custom substate is active in. "elapsed" will always equal to 1, no matter the FPS.

  • onCustomSubstateUpdatePost(name:String, elapsed:Float)

    - Called after every frame that your custom substate is active in. "elapsed" will always equal to 1, no matter the FPS.

  • onCustomSubstateDestroy(name:String)

    - Called when your custom substate is destroyed.

  • onVideoCompleted(name:String, skipped:Bool)

    - Called when a video cutscene has finished playing. "name" is the filepath/name of the video determined by the first argument and "skipped" will be true if the video cutscene was... skipped.


  • LUA exclusive callbacks

  • onCountdownTick(counter:Int)

    - Called everytime the coundown ticks down. "counter" can be: 0 ("Three"), 1 ("Two"), 2 ("One"), 3 ("Go!"), or 4 (triggered at the same time as onSongStart).

  • onSpawnNote(id:Int, data:Int, type:String, isSustainNote:Bool, strumTime:Float)

    - Called when a note is spawned in game.

  • goodNoteHitPre(id:Int, direction:Int, noteType:String, isSustainNote:Bool)

    - Called before a note was hit.

  • goodNoteHit(id:Int, direction:Int, noteType:String, isSustainNote:Bool)

    - Called when a note was hit.

  • opponentNoteHitPre(id:Int, direction:Int, noteType:String, isSustainNote:Bool)

    - Called before the opponent hits one of their notes.

  • opponentNoteHit(id:Int, direction:Int, noteType:String, isSustainNote:Bool)

    - Called when the opponent hits one of their notes.

  • noteMiss(id:Int, direction:Int, noteType:String, isSustainNote:Bool)

    - Called when you miss a note.

  • onTweenCompleted(tag:String)

    - Called when a tween made by any of the tween LUA functions was completed. "tag" is the name/tag of the tween.

    Note: onTweenCompleted is pointless for "startTween" since you can set it's "onComplete" field.

  • onTimerCompleted(tag:String, loops:Int, loopsLeft:Int)

    - Called when a timer made by "startTimer" is completed. "tag" is the name/tag of the timer, "loops" is how many times the timer had looped, if the timer is set to loop a specific amount of times, and "loopsLeft" is how many loops the timer has left to complete, if set to loop.

  • onSoundFinished(tag:String)

    - Called when a sound created by "playSound" is finished. "tag" is the tag of the sound.

    Note: onSoundFinished will only be called if you have the "tag" argument of "playSound" set.


  • HScript exclusive callbacks

  • onCountdownTick(tick:Countdown, counter:Int)

    - Called everytime the coundown ticks down. "tick" can be: Countdown.THREE ("Three"), Countdown.TWO ("Two"), Countdown.ONE ("One"), Countdown.GO ("Go!"), or Countdown.START (triggered at the same time as onSongStart).

    Note: onCountdownTick has the counter parameter just like it's LUA counterpart, but it's basically the same thing.

  • onSpawnNote(note:Note)

    - Called when a note is spawned in game.

  • goodNoteHitPre(note:Note)

    - Called before a note was hit.

  • goodNoteHit(note:Note)

    - Called when a note was hit.

  • opponentNoteHitPre(note:Note)

    - Called before the opponent hits one of their notes.

  • opponentNoteHit(note:Note)

    - Called when the opponent hits one of their notes.

  • noteMiss(note:Note)

    - Called when you miss a note.