Skip to content

Lua Functions and Callbacks

Mayo78 edited this page Feb 15, 2023 · 5 revisions

Global

Functions

all playstate functions that didn't reference anything to do with playstate are global, otherwise they are playstate specific

doTween(object:String, vars:Lua.LUATTABLE, duration:Float, options:Lua.LUATTABLE)

Lua.LUATTABLE is the basic lua table/array

Acts like FlxTween.tween in haxe, ex:

doTween('boyfriend', {x = 0, y = 24, ['scale.x'] = 0.5}, 2, {ease = 'cubeOut', onComplete = function()
    debugPrint 'tween DONE!'
end})

timer(time:Float, finishCallback:Void->Void)

CURRENTLY BROKEN AT THE TIME OF WRITING THIS!

runs an anonymous timer with a callback, ex:

timer(0.5, function()
    debugPrint 'hiiiiiiiiiiiiii'
end)

controls(control:String)

gets a control from the controls object, ex:

if controls 'UI_LEFT_P' then
    debugPrint 'left just pressed!'
end

switchState(state:String)

switches to a musicbeatstate from just a string, ex:

if goToNextState then
    switchState 'TitleState'
end

callMethod(method:String, args:Array)

calls a function in the current state by the name given, ex:

callMethod('method', {1, 2, 3})

setGlobalProperty(field:String, value:Dynamic)

sets a global property that can be used in any state

getGlobalProperty(field:String)

returns a global property

enterSong(song:String, diff:String)

enters a song without difficulty number nonsense, ex:

enterSong('fresh', 'hard')

getGameplayChanger(changer:String)

returns a gameplay changers value

getClientPref(pref:String)

returns a client preference

makeMenuBG(tag:String, x:Float, y:Float, ?color:Int, ?image:String)

makes a sprite with a randomized background or the default background

setMenuBgs(bgs:Array)

sets the randomized backgrounds to the inputted array

saveSet(field:String, value:Dynamic)

saveGet(field:String)

setVar(field:String, value:Dynamic)

sets a field inside the variables map, usually used by hscript

contains(table:Array, thing:Dynamic)

indexOf(table:Array<Dynamic, thing:Dynamic)

Callbacks

onCreate()

onCreatePost()

onUpdate()

onUpdatePost()

onStepHit()

onBeatHit()

onSectionHit()

onInitLua()

called when every lua script is finished loading

onCall(event:String, args:Array)

called every time another function is called

TitleState

Functions

createCoolText(text:Array, ?offset:Float)

addMoreText(text:String, ?offset:Float)

Callbacks

onCreateTitle()

Can be stopped with Function_Stop

called right before the title state is created, this really isn't that useful anymore with initial state support

onIntroStart()

called when the main intro starts (with the text)

sickBeatHit(beat:Int)

like onBeatHit, but for the intro text

onSkipIntro()

this is called when the intro ends

MainMenuState

Callbacks

onExit()

Can be stopped with Function_Stop

called when the user exits the state

onExitPost()

called right before the state is about to switch

onAccept()

called when the user accepts

onSelect()

Can be stopped with Function_Stop

called when the game is about to switch to a new state

FreeplayState

Functions

getSongs()

returns an array of objects, theres an object for each song that contains things like the song name, color, character, ect. ex:

for i,song in pairs(getSongs()) do
    debugPrint(song.songName)
end

addGameplayChanger(changer)

ONLY USE IN THE getOptions CALLBACK!

adds a gameplay changer from a table. The table has all the properties named out, to see what properties you can have you can see the typedef here, ex:

addGameplayChanger{
    text = 'cool mode',
    type = 'bool',
    variable = 'coolmode', --variable to get with getGameplayChanger
    defaultValue = false
}

Callbacks

onAddSong(songName, weekNum, songCharacter, color)

Can be stopped with Function_Stop

called when a song is added to the song list

onExit()

Can be stopped with Function_Stop

called when the user exits the state

onExitPost()

called right before the state is about to switch

onSongPicked(songLowercase, curDifficulty, pressingShift)

Can be stopped with Function_Stop

called before the song json is loaded, only stop this for things like the dnb 3.0 terminal

onSongLoaded(songLowercase, curDifficulty, pressingShift)

Can be stopped with Function_Stop

called after the song is successfully loaded, use this for character select screens so you can just switchState 'playstate'

onSongResetScore(song, difficulty, character)

called when the user resets the score to a song

onChangeDifficulty(change)

called when the user changes the difficulty

onChangeDifficultyPost(change)

called after the difficulty was changed

onChangeSelection(change, playedSound)

called when the user changes the song

onChangeSelectionPost(change, playedSound)

called after the song was changed

getOptions()

called when the gameplay changers are added

OptionsState (and its substates)

Functions

addState(state:String)

use this to add another option menu

addOption(option)

ONLY USE IN THE onOptionsAdded CALLBACK!

adds an option from a table. The table has all the properties named out, to see what properties you can have you can see the typedef here, ex:

addOption{
    name = 'side scroll',
    description = 'the notes go SIDEWAYS!',
    variable = 'sidescroll',
    type = 'bool',
    defaultValue = false
}

Callbacks

onOptionsAdded(title)

called when the options in that specific state are loaded, this is where you can add your own options

Clone this wiki locally