Skip to content

Conditional related functions

9thCore edited this page Mar 19, 2023 · 2 revisions

The functions and variables on this page are available by loading the conditional.lua extension. It is loaded by default.

level:customconditional(name, expression)

Returns a new conditional object whose name is name.
When the conditional is run, its expression will be checked.

Example:

myConditional = level:customconditional('my conditional', 'i0 == 2') -- A conditional that will check if i0 is equal to 2

level:custom(name, expression)

Alias for level:customconditional

level:lasthitconditional(name, row, result)

Returns a new conditional object whose name is name.
When the conditional is run, row row's last hit will be checked against result.
If row is -1, this conditional will check if any row's last hit was result, and if it's 0 or higher, it will check that specific row (0-indexed).
row can also be a row object.
Result can be any of the following: 'VeryEarly', 'SlightlyEarly', 'Perfect', 'SlightlyLate', 'VeryLate', 'AnyEarlyOrLate' or 'Missed'.

Example:

myConditional2 = level:lasthitconditional('my conditional', -1, 'Missed') -- A conditional that will check if any row's last hit was a complete miss

level:lasthit(name, row, result)

Alias for level:lasthitconditional

level:timesexecutedconditional(name, times)

Returns a new conditional object whose name is name.
When the conditional is run, it checks how many times the event it's on has run. If it ran for less than times times, it will run again - or in other words, it ensures the event will run at most times times.

Example:

myConditional3 = level:timesexecutedconditional('my conditional', 3) -- A conditional that will ensure the event it's attached to will run at most 3 times

level:timesexecuted(name, row, result)

Alias for level:timesexecutedconditional

level:languageconditional(name, language)

Returns a new conditional object whose name is name.
When the conditional is run, it checks if the player's current language is language.
language can be any of the following: 'English', 'Spanish', 'Portuguese', 'ChineseSimplified', 'ChineseTraditional', 'Korean', 'Polish', 'Japanese', German'`.

Example:

myConditional4 = level:languageconditional('my conditional', 'English') -- A conditional that will check if the player's language is set to English

level:language(name, language)

Alias for level:languageconditional

level:playermodeconditional(name, isTwoPlayer)

Returns a new conditional object whose name is name.
When the conditional is run, it checks if the level is being played in two player mode.
isTwoPlayer is a boolean.

Example:

myConditional5 = level:playermodeconditional('my conditional', true) -- A conditional that will check if the level is being played in two player mode

level:playermode(name, isTwoPlayer)

Alias for level:playermodeconditional

conditional:red(isRed)

If isRed is true, the conditional is set to red mode. Otherwise, it's set to blue mode.
Red mode means that the conditional will allow the event to run if its conditions are not met.

Example:

myConditional:red(true) -- Now this conditional will allow the event to run if i0 is different from 2

level:conditional(conditionals, duration, func)

Attaches conditionals to the events created after this function with a duration of duration beats.
conditionals can either be a list of conditional objects or one conditional object.
duration is a number, representing how many beats the game should check for the conditionals on the event after the playbar passes said event.
func is an optional argument, a function. If supplied, it will run the function and then level:endconditional() after.

Example:

level:conditional({myConditional, myConditional2}, 1) -- Sets the conditionals of the next events to myConditional and myConditional2 and a duration of 1 beat
row:setborder(1, 'Outline', '00FF00', 50, 1, 'Linear') -- This event now has the conditionals mentioned above attached to it
myConditional:red(true) -- Make myConditional red, running if i0 is different from 2
row:setborder(1.5, 'Outline', '00FF00', 50, 1, 'Linear') -- Event with red myConditional and blue myConditional2
level:endconditional()

myConditional3:red(true)
level:conditional(myConditional3, 0, function()
  row:setborder(2, 'Outline', 'FF0000', 100, 4, 'Linear') -- As this is inside of a function supplied to level:conditional, it will have myConditional3, but the event outside of the function won't!
end)
row:setborder(3, 'Outline', '0000FF', 50, 1, 'Linear') -- Free from the shackles of conditionals

level:endconditional()

Stops a previous level:conditional() call, so events created after this function will no longer have conditionals attached to them.

Example:

level:conditional({myConditional, myConditional2, myConditional3, myConditional4, myConditional5}, 0)
row:setborder(1, 'Outline', 'FF0000', 50, 1, 'Linear')
level:endconditional() -- Begone, conditionals
row:setborder(2, 'Outline', '0000FF', 50, 1, 'Linear')