Lua - ikemen-engine/Ikemen-GO GitHub Wiki

Ikemen GO engine is written in golang programming language. On top of it the engine uses Lua as an embedded scripting language, allowing the application functionality to be adjusted after it has been built.

Among others, Lua scripts are responsible for following tasks:

  • Logic behind everything that is displayed outside fight (including screenpack logic, which controls interface rendering)
  • Features expanding match functionality: Stuff like continue screen, pause menu etc.)
  • Game modes logic: The engine is responsible for actual fighting. Who will enter the match and what to do with the match result is handled by external Lua scripts.
  • Game configuration

Default Lua scripts are available within external/script directory. Due to the fact that scripts are often updated and expanded between versions, any changes made to them locally may not be forward compatible with future engine releases (at least until the engine stabilizes feature wise). For this reason editing scrips directly is not recommended for normal players that use the engine as a Mugen replacement, but for full game makers who decide to branch off to tailor the scripts to work exactly as they need (or don't mind extra work in case of code conflicts).

Following sections briefly showcase some of the features that use Lua and at the same time don't require editing default Lua scripts directly. Article dedicated to Arcade Paths / Story Mode arcs also brings up the topic of external Lua scripts.

Explanation how Lua language works or how to edit default scripts to your liking is outside scope of this article. Refer to Lua 5.1 reference manual and dedicated sites specializing in teaching programming languages instead (e.g. 1, 2).

Current iteration of Lua scripts support in-game unlocking of characters, stages and game modes via optional select.def and screenpack parameters.

Character unlocking

Characters locked via select.def hidden parameter can be unlocked using unlock parameter assigned in the same line. Everything that follows unlock parameter is treated as pure Lua code (which means it has to be very last parameter in line). Lua code condition is executed each time the mode is initiated and upon returning to main menu. It should return boolean data type. If the code evaluates to boolean true the character locked via select.def hidden parameter becomes selectable. If the character has been unlocked, but later on the condition returns false, such character becomes locked again.

example 1

Below is an example of unlocking SuaveDude character based on data gathered during matches (by default used for generating hiscores).

When the game is started, data present within saves/stats.json file is read into a Lua table called stats (table structure is the same as in json file). Let's say you want to unlock the character only if player has finished arcade mode (made it to the end defeating final boss) at least once. In such case unlocking condition (pasted right after unlock = parameter in select.def line that adds hidden character) can look for example as follows:

stats.modes ~= nil and stats.modes.arcade ~= nil and stats.modes.arcade.clear >= 1

Above code will return true if condition is met, unlocking SuaveDude as a result, or false if player has not finished arcade mode at least once or deleted old stats.json file. Appropriate table existence checks are needed before reading the value - otherwise script execution would crash if the subtable is missing)

example 2

Let's say we want to make SuaveDude available in all modes, but not in "Boss Rush". In such case the unlock condition can look like this (using one of the functions that returns the same data as GameMode trigger)

gamemode() ~= "bossrush"

example 3

Due to how online play works (only inputs being sent over, which means both players essentially need the same game, including exactly the same looking and behaving select screens), having additional condition that ensures that characters and stages are unlocked during netplay is recommended. network() function returns true only in online modes, so it can be used for this purpose, for example like this:

(--[[here goes normal condition for unlocking, like in example 1 and 2]]) or network()

example 4

As explained in select.def, character parameters are defined in the same line as the character itself, which limits complexity of code that can be written there. For this reason, for more complicated conditions, it's worth to prepare Lua function (loaded via external modules functionality) and call it instead.

--function declared via external module
function myFunction(myArgument)
  --any Lua code goes here. The function should return boolean data type (true or false)
end

Stage unlocking

As above but the select.def unlock parameter is assigned as stage parameter.

Game Mode unlocking

Game Modes can be locked in screenpack DEF file, under [Title Info] section, by using special menu.unlock.<itemname> parameter (where <itemname> should replaced with itemname parameter associated with particular mode in main menu). Text assigned to this parameter is read as a pure Lua code and works in similar fashion to character and stages unlocking (mode will be visible only if the parameter is missing or if it returns true, otherwise the mode is hidden). Unlike characters and stages, game modes unlocking is runtime permanent (as soon as the mode is unlocked, the condition won't be checked again, until the game is restarted).

External lua scripts (let's call them modules) are meant to implement features coded in Lua without directly modifying scripts distributed with engine.

There are 3 alternative ways to load external modules. Modules are loaded after all default scripts in following order:

  1. Any file with lua extension placed in external/mods directory will be loaded automatically (alphabetical order)
  2. Paths to lua files can be added into save/config.json Modules table (in the same way as files are added to config.json CommonStates)
  3. Screenpack can be distributed with its own lua file, referenced in DEF file, under [Files] section, via module = path_to_lua_file parameter

Keep in mind that despite external modules making your script changes portable (easy to share and not being overwritten by the engine itself upon update), we can't promise that these files will be always compatible with future engine iterations. For example functions overwritten by a module may be changed in a way that your code is not ready for. Ikemen GO Lua code itself could also benefit from a major refactoring effort, so if anyone will ever bother to do it, it could lead to major changes to the scripts flow and logic.

In most cases using modules requires good understanding of scripts distributed with the engine (you need to know how something has been implemented in order to override how it works or expand its current functionality). As an example here is an external module code that adds completely new game mode, without need to edit any of the existing Lua scripts.

-- main.t_itemname is a table storing functions with general game mode
-- configuration (usually ending with start.f_selectMode function call).
main.t_itemname.vs100kumite = function()
	main.f_playerInput(main.playerInput, 1)
	main.t_pIn[2] = 1
	main.aiRamp = false
	main.charparam.ai = true
	main.charparam.music = true
	main.charparam.single = true
	main.charparam.stage = true
	main.charparam.time = true
	main.dropDefeated = false -- defeated members are not removed from team
	main.elimination = false -- single lose doesn't stop further lua execution
	main.exitSelect = true
	main.forceRosterSize = true -- roster size enforced even if there are not enough characters to fill it
	--main.lifebar.match = true
	--main.lifebar.p2ailevel = true
	main.persistLife = true -- life maintained after match
	main.persistMusic = true -- don't stop the previous music at the start of the match.
	main.persistRounds = true -- lifebar uses consecutive wins for round numbers
	main.makeRoster = true
	main.motif.continuescreen = false -- no continue screen after we lose the match
	main.motif.hiscore = true
	main.motif.losescreen = false -- no lose screen after we lose the match
	main.motif.winscreen = true
	main.matchWins.draw = {0, 0}
	main.matchWins.simul = {1, 1}
	main.matchWins.single = {1, 1}
	main.matchWins.tag = {1, 1}
	main.orderSelect[1] = true
	main.orderSelect[2] = true
	main.rotationChars = true
	main.stageMenu = true
	main.storyboard.credits = true
	main.storyboard.gameover = true
	main.teamMenu[1].ratio = true
	main.teamMenu[1].simul = true
	main.teamMenu[1].single = true
	main.teamMenu[1].tag = true
	main.teamMenu[1].turns = true
	main.teamMenu[2].ratio = true
	main.teamMenu[2].simul = true
	main.teamMenu[2].single = true
	main.teamMenu[2].tag = true
	main.teamMenu[2].turns = true
	textImgSetText(motif.select_info.title.TextSpriteData, motif.select_info.title.text.vs100kumite)
	setGameMode('vs100kumite')
	hook.run("main.t_itemname")
	return start.f_selectMode
end

This is enough to make your external mode functional within engine. Don't forget to also add it to your screenpack DEF file, as explained in this article.

Since external modules code is loaded after default lua scripts, while having access to everything initiated before it, it's also possible to overwrite any function or table present in default script, without touching the file directly. The more intrusive the change is the higher chance that it won't be forward compatible though.

Format: launchFight{args}

Required arguments: none

Return: bool Returns false if further lua script execution should be stopped (based on function parameter and match result), otherwise true

Optional arguments:

continue = bool (true or false) Decides if character is allowed to continue and rematch lost or draw fight. If false the continue screen won't show up but the lua script execution continues. (this can be useful for example for branching storyline on defeat)

  • default arcade path: true
  • default story mode: true

quickcontinue = bool (true or false) Decides if player is allowed to select new character after continue screen. If false the rematch is done with the same character.

  • default arcade path: value heritage from options
  • default story mode: true regardless of what is set (select screen is disabled in story mode)

order = num (int) Random selection limited to characters with this order.

  • default arcade path: 1
  • default story mode: 1

p1char = {list} (table) List of characters (names/paths enclosed in quotation, separated by commas) to assign to p1 team side.

  • default arcade path: characters chosen in select screen
  • default story mode: previously assigned chars

p1pal = num (int) (nightly build only) Forces particular pal to p1.

p1numchars = num (int) Forces particular team size.

  • default arcade path: team size chosen during select screen, but not less than p1char count
  • default story mode: at least 1, but not less than p1char count

p1numratio = {numlist} (int) List of ratio settings (1-4) to assign to p1 team side characters if turns team mode is selected. Example for 3 players: p1numratio = {1, 1, 2}

  • default arcade path: same as the ratio chosen during select screen, not assigned otherwise
  • default story mode: not assigned

p1teammode = "mode" (string) Assigns p1 team mode to single, simul, tag or turns.

  • default arcade path: team mode chosen during select screen
  • default story mode: single

p1rounds = num (int) Number of rounds p1 has to lose to be considered defeated.

  • default arcade path: value heritage from options
  • default story mode: value heritage from options

p1orderselect = bool (true or false) Decides if p1 is allowed to switch team order.

  • default arcade path: true
  • default story mode: false

p2char = {list} (table) List of characters (names/paths enclosed in quotation, separated by commas) to assign to p2 team side.

  • default arcade path: random characters with the particular order, up to the team size chosen in the select screen
  • default story mode: 1 random characters with the particular order

p2pal = num (int) (nightly build only) Forces particular pal to p2.

p2numchars = num (int) Forces particular team size.

  • default arcade path: team size chosen during select screen, but not less than p2char count
  • default story mode: at least 1, but not less than p2char count

p2numratio = {numlist} (int) List of ratio settings (1-4) to assign to p2 team side characters if turns team mode is selected. Example for 3 players: p2numratio = {1, 1, 2}

  • default arcade path: follows arcade.ratiomatches select.def settings in arcade, if selected, not assigned otherwise
  • default story mode: not assigned

p2teammode = "mode" (string) Assigns p2 team mode to single, simul, tag or turns.

  • default arcade path: team mode chosen during select screen
  • default story mode: single

p2rounds = num (int) Number of rounds p2 has to lose to be considered defeated.

  • default arcade path: rounds assigned as select.def parameter or value heritage from options
  • default story mode: value heritage from options

p2orderselect = bool (true or false) Decides if p2 is allowed to switch team order.

  • default arcade path: true
  • default story mode: false

exclude = {list} (table) List of characters (names/paths enclosed in quotation, separated by commas) to exclude from random selection (affects only this match, characters are still available during next function call). Characters that we've already fought against in the current arcade run with this character are automatically excluded.

  • default arcade path: empty list
  • default story mode: empty list

music = {"path", volume, loopstart, loopend} (table) Music that should be used at the start of round. path string can be optionally followed by volume, loopstart and loopend values.

  • default arcade path: music assigned as select.def parameter or default stage music
  • default story mode: default stage music

round.music = {"path", volume, loopstart, loopend} (table) Music that should be used at the start of round. path string can be optionally followed by volume, loopstart and loopend values. (typed as number) portion of key name decides round on which the music will be played

  • default arcade path: music assigned as select.def parameter or default stage music
  • default story mode: default stage music

final.music = {"path", volume, loopstart, loopend} (table) Music used at the start of the final round. path string can be optionally followed by volume, loopstart and loopend values. (typed as number) portion of key name decides round on which the music will be played

  • default arcade path: music assigned as select.def parameter or default stage music
  • default story mode: default stage music

life.music = {"path", volume, loopstart, loopend} (table) Music that should be used when player's controlled character has (by default) less than 30% life during deciding round. Further adjustments available via stage DEF file. path string can be optionally followed by volume, loopstart and loopend values.

  • default arcade path: music assigned as select.def parameter or default stage music
  • default story mode: default stage music

victory.music = {"path", volume, loopstart, loopend} (table) Music file that should start right after character scores final round K.O. and continue throughout the victory screen. path string can be optionally followed by volume, loopstart and loopend values, separated by commas.

  • default arcade path: music assigned as select.def parameter or default stage music
  • default story mode: default stage music

stage = "path" (string) Path to the stage to be used in this match.

  • default arcade path: stage assigned as select.def parameter or randomized
  • default story mode: randomized

ai = ailevel (float) Set a float value between 1 and 8 to force AI Level regardless of difficulty and AI ramping settings.

  • default arcade path: ai assigned as select.def parameter or value following AI ramping settings
  • default story mode: value heritage from options

time = num (int) Overwrites round time (in seconds) for this match.

  • default arcade path: value heritage from options, adjusted by tag team size
  • default story mode: value heritage from options, adjusted by tag team size

vsscreen = bool (true or false) Decides if versus screen should be shown before fight.

  • default arcade path: true
  • default story mode: false

victoryscreen = bool (true or false) Decides if victory screen should be shown after fight.

  • default arcade path: true
  • default story mode: false

lua = "code" (string) Lua code that will be executed each frame during match. (e.g. call your custom function to store extra match data gathered via Lua version of CNS/ZSS style triggers)

launchFight{
	p2char = {"Juni", "Juli"},
	p2numchars = 2,
	p2teammode = "simul",
	p2rounds = 1,
	time = 60,
	stage = "stages/dolls.def",
	["victory.music"] = {"sound/kfm.mp3", 100, 0, 0}
}

Format: launchStoryboard(path)

Return: bool Returns false if storyboard doesn't exist, otherwise true

Required arguments: path of the storyboard to execute

launchStoryboard('chars/kfm/intro.def')

Below are the documented embedded Lua functions exposed by the engine.

TODO: Change the LDoc documentation formatting to proper wiki-style Markdown.

--- Add a character definition to the select screen.
-- @function addChar
-- @tparam string defpath Path to the character `.def` file (relative to `chars/` or absolute).
-- @tparam[opt] string params Optional comma-separated parameter string (from select.def)
-- @treturn boolean success `true` if the character was added successfully, `false` otherwise.
function addChar(defpath, params) end

--- Register a global keyboard shortcut that runs Lua code.
-- @function addHotkey
-- @tparam string key Key name as used by the engine (for example `"F1"`, `"C"`, etc.).
-- @tparam[opt=false] boolean ctrl If `true`, the Ctrl key must be held.
-- @tparam[opt=false] boolean alt If `true`, the Alt key must be held.
-- @tparam[opt=false] boolean shift If `true`, the Shift key must be held.
-- @tparam[opt=false] boolean allowDuringPause If `true`, the hotkey also works while the game is paused.
-- @tparam[opt=false] boolean debugOnly If `true`, the hotkey is treated as a debug key
--   and only works when debug input is allowed.
-- @tparam string script Lua code to execute when the shortcut is pressed.
-- @treturn boolean success `true` if the shortcut was registered, `false` if the key name is invalid.
function addHotkey(key, ctrl, alt, shift, allowDuringPause, debugOnly, script) end

--- Add a stage definition to the select screen.
-- @function addStage
-- @tparam string defpath Path to the stage `.def` file (relative to `stages/` or absolute).
-- @tparam[opt] string params Optional comma-separated parameter string (from select.def)
-- @treturn boolean success `true` if the stage was added successfully, `false` otherwise.
function addStage(defpath, params) end

--- Add an offset to an animation's current position.
-- @function animAddPos
-- @tparam Anim anim Animation userdata.
-- @tparam float32 dx Offset to add on the X axis.
-- @tparam float32 dy Offset to add on the Y axis.
function animAddPos(anim, dx, dy) end

--- Copy velocity parameters from one animation to another.
-- @function animApplyVel
-- @tparam Anim target Target animation userdata to modify.
-- @tparam Anim source Source animation userdata whose velocity/accel settings are copied.
function animApplyVel(target, source) end

--- Print debug information about an animation to the console.
-- @function animDebug
-- @tparam Anim anim Animation userdata.
-- @tparam[opt] string prefix Optional text prefix printed before the debug info.
function animDebug(anim, prefix) end

--- Queue drawing of an animation on a render layer.
-- @function animDraw
-- @tparam Anim anim Animation userdata.
-- @tparam[opt] int16 layer Render layer index; if omitted, the animation's own `layerno` is used.
function animDraw(anim, layer) end

--- Get timing information for an animation.
-- @function animGetLength
-- @tparam Anim anim Animation userdata.
-- @treturn int32 length Effective animation length in ticks (as returned by `Anim.GetLength()`).
-- @treturn int32 totaltime Raw `totaltime` field from the underlying `Animation`.
function animGetLength(anim) end

--- Get a preloaded character animation by sprite group/number.
-- @function animGetPreloadedCharData
-- @tparam int32 charRef Character slot index in the select definition (1-based).
-- @tparam int32 group Sprite group number.
-- @tparam int32 number Sprite number.
-- @tparam[opt] boolean keepLoop If `false` and the animation's `totaltime` equals `looptime`,
--   the animation is converted to an infinite loop (`totaltime = -1`, `looptime = 0`).
-- @treturn[1] Anim anim A new `Anim` userdata wrapping the preloaded animation.
-- @treturn[0] nil If no matching animation exists.
function animGetPreloadedCharData(charRef, group, number, keepLoop) end

--- Get a preloaded stage animation by sprite group/number.
-- @function animGetPreloadedStageData
-- @tparam int32 stageRef Stage slot index in the select definition (1-based).
-- @tparam int32 group Sprite group number.
-- @tparam int32 number Sprite number.
-- @tparam[opt] boolean keepLoop If `false` and the animation's `totaltime` equals `looptime`,
--   the animation is converted to an infinite loop (`totaltime = -1`, `looptime = 0`).
-- @treturn[1] Anim anim A new `Anim` userdata wrapping the preloaded animation.
-- @treturn[0] nil If no matching animation exists.
function animGetPreloadedStageData(stageRef, group, number, keepLoop) end

--- Get information about the current sprite used by an animation.
-- @function animGetSpriteInfo
-- @tparam Anim anim Animation userdata.
-- @tparam[opt] int32 group Optional explicit sprite group to query.
-- @tparam[opt] int32 number Optional explicit sprite number to query.
--   If `group`/`number` are omitted, the animation's current sprite is used.
-- @treturn[1] table info A table:
--   - `Group` (int32) sprite group number  
--   - `Number` (int32) sprite number  
--   - `Size` (int32[2]) `{width, height}`  
--   - `Offset` (int32[2]) `{x, y}` default origin offset  
--   - `palidx` (int32) current palette index used for this sprite
-- @treturn[0] nil If no sprite is available.
function animGetSpriteInfo(anim, group, number) end

--- Load palettes for an animation's underlying sprite file, if palette usage is enabled.
-- @function animLoadPalettes
-- @tparam Anim anim Animation userdata.
-- @tparam int32 param Palette parameter passed to `loadCharPalettes` (engine-specific semantics).
function animLoadPalettes(anim, param) end

--- Create a new animation from a sprite file and action definition.
-- @function animNew
-- @tparam[opt] Sff sff Sprite file userdata to use. If omitted or invalid,
--   a new empty SFF is created internally.
-- @tparam string|Animation actOrAnim Either:
--   - a string definition of the animation to load, or
--   - an `Animation` userdata (for example from `motif.AnimTable[...]`).
-- @treturn Anim anim Newly created animation userdata.
function animNew(sff, actOrAnim) end

--- Prepare an animation so that each character can apply its own palette.
-- @function animPrepare
-- @tparam Anim anim Source animation userdata.
-- @tparam int32 charRef Character slot index in the select definition (1-based).
-- @treturn Anim preparedAnim Either a copy with adjusted palette data (when palette
--   usage is enabled) or the original `anim` when palette handling is disabled.
function animPrepare(anim, charRef) end

--- Reset an animation to its initial state, fully or partially.
-- @function animReset
-- @tparam Anim anim Animation userdata.
-- @tparam[opt] table what Optional table of reset keys. If omitted, everything is reset.
--   Each value must be a string (case-insensitive) among:
--   - `"anim"`: reset the underlying `Animation` (frame/time)  
--   - `"pos"`: reset position to initial offset  
--   - `"scale"`: reset scale to initial values  
--   - `"window"`: reset clipping window to initial value  
--   - `"velocity"`: reset velocity to initial value  
--   - `"palfx"`: clear attached palette effects  
function animReset(anim, what) end

--- Set gravity/acceleration applied to an animation.
-- @function animSetAccel
-- @tparam Anim anim Animation userdata.
-- @tparam float32 ax Horizontal acceleration.
-- @tparam float32 ay Vertical acceleration.
function animSetAccel(anim, ax, ay) end

--- Set alpha blending for an animation.
-- @function animSetAlpha
-- @tparam Anim anim Animation userdata.
-- @tparam int16 src Source alpha factor (0–256, engine-specific).
-- @tparam int16 dst Destination alpha factor (0–256, engine-specific).
function animSetAlpha(anim, src, dst) end

--- Replace an animation's underlying `Animation` data.
-- @function animSetAnimation
-- @tparam Anim anim Animation userdata to modify.
-- @tparam string|Animation actOrAnim Either:
--   - a string definition of the animation to load, or
--   - an `Animation` userdata (for example from `Motif.AnimTable[...]`).
function animSetAnimation(anim, actOrAnim) end

--- Set friction applied to an animation's velocity.
-- @function animSetFriction
-- @tparam Anim anim Animation userdata.
-- @tparam float32 fx Horizontal friction.
-- @tparam float32 fy Vertical friction.
function animSetFriction(anim, fx, fy) end

--- Set the render layer used by an animation.
-- @function animSetLayerno
-- @tparam Anim anim Animation userdata.
-- @tparam int16 layer Layer index to draw this animation on.
function animSetLayerno(anim, layer) end

--- Set the local coordinate system for an animation.
-- @function animSetLocalcoord
-- @tparam Anim anim Animation userdata.
-- @tparam float32 width Local coordinate width.
-- @tparam float32 height Local coordinate height.
function animSetLocalcoord(anim, width, height) end

--- Set the color key (transparent index) used by an animation.
-- @function animSetColorKey
-- @tparam Anim anim Animation userdata.
-- @tparam int16 index Palette index used as the transparency key.
function animSetColorKey(anim, index) end

--- Set the facing (horizontal flip) of an animation.
-- @function animSetFacing
-- @tparam Anim anim Animation userdata.
-- @tparam float32 facing Facing multiplier, usually `1` or `-1`.
function animSetFacing(anim, facing) end

--- Set maximum drawing distance (clipping bounds) for an animation.
-- @function animSetMaxDist
-- @tparam Anim anim Animation userdata.
-- @tparam float32 maxX Maximum horizontal distance.
-- @tparam float32 maxY Maximum vertical distance.
function animSetMaxDist(anim, maxX, maxY) end

--- Configure palette effects for an animation.
-- @function animSetPalFX
-- @tparam Anim anim Animation userdata.
-- @tparam table palfx Table of palette effect fields:
--   - `time` (int32): duration in ticks  
--   - `add` (table int32[3]): additive RGB components  
--   - `mul` (table int32[3]): multiplicative RGB components  
--   - `sinadd` (table int32[4]): sinusoidal add `{r, g, b, period}`; negative period flips sign  
--   - `sinmul` (table int32[4]): sinusoidal mul `{r, g, b, period}`; negative period flips sign  
--   - `sincolor` (table int32[2]): sinusoidal color shift `{amount, period}`  
--   - `sinhue` (table int32[2]): sinusoidal hue shift `{amount, period}`  
--   - `invertall` (boolean|number): whether to invert all colors (`1`/`true` to enable)  
--   - `invertblend` (int32): invert blend mode index  
--   - `color` (float32): color saturation factor (`0–256` scaled to `0.0–1.0`)  
--   - `hue` (float32): hue adjustment factor (`0–256` scaled to `0.0–1.0`)  
function animSetPalFX(anim, palfx) end

--- Set animation position, optionally overriding only one axis.
-- @function animSetPos
-- @tparam Anim anim Animation userdata.
-- @tparam[opt] float32 x New X position; if omitted, initial X offset is used.
-- @tparam[opt] float32 y New Y position; if omitted, initial Y offset is used.
function animSetPos(anim, x, y) end

--- Set the scale of an animation.
-- @function animSetScale
-- @tparam Anim anim Animation userdata.
-- @tparam float32 sx Horizontal scale factor.
-- @tparam float32 sy Vertical scale factor.
function animSetScale(anim, sx, sy) end

--- Configure tiling for an animation.
-- @function animSetTile
-- @tparam Anim anim Animation userdata.
-- @tparam boolean tileX If `true`, tile horizontally.
-- @tparam boolean tileY If `true`, tile vertically.
-- @tparam[opt] int32 spacingX Horizontal tile spacing in pixels.
-- @tparam[opt] int32 spacingY Vertical tile spacing in pixels (defaults to `spacingX` if omitted).
function animSetTile(anim, tileX, tileY, spacingX, spacingY) end

--- Set the base velocity of an animation.
-- @function animSetVelocity
-- @tparam Anim anim Animation userdata.
-- @tparam float32 vx Horizontal velocity.
-- @tparam float32 vy Vertical velocity.
function animSetVelocity(anim, vx, vy) end

--- Set the clipping window for an animation.
-- @function animSetWindow
-- @tparam Anim anim Animation userdata.
-- @tparam float32 x1 Left coordinate of the clipping window.
-- @tparam float32 y1 Top coordinate of the clipping window.
-- @tparam float32 x2 Right coordinate of the clipping window.
-- @tparam float32 y2 Bottom coordinate of the clipping window.
function animSetWindow(anim, x1, y1, x2, y2) end

--- Set the X shear factor applied when drawing an animation.
-- @function animSetXShear
-- @tparam Anim anim Animation userdata.
-- @tparam float32 shear X shear factor.
function animSetXShear(anim, shear) end

--- Set the rotation angle applied when drawing an animation.
-- @function animSetAngle
-- @tparam Anim anim Animation userdata.
-- @tparam float32 angle Rotation angle (degrees).
function animSetAngle(anim, angle) end

--- Set rotation angle around the X axis for an animation.
-- @function animSetXAngle
-- @tparam Anim anim Animation userdata.
-- @tparam float32 xangle X-axis rotation angle (engine-specific units, usually degrees).
function animSetXAngle(anim, xangle) end

--- Advance an animation by one tick. By default, only the first call per frame advances the animation.
-- @function animUpdate
-- @tparam Anim anim Animation userdata.
-- @tparam[opt] bool force Force update; when true, advance the animation even if it was already updated this frame.
function animUpdate(anim, force) end

--- Queue drawing of many animations in one call.
-- @function batchDraw
-- @tparam table batch Array-like table of draw items. Each item is a table:
--   - `anim` (Anim) animation userdata  
--   - `x` (float32) X position  
--   - `y` (float32) Y position  
--   - `facing` (float32) facing multiplier (usually `1` or `-1`)  
--   - `layerno` (int16, optional) layer override; defaults to `anim.layerno`  
function batchDraw(batch) end

--- Queue drawing of a background definition.
-- @function bgDraw
-- @tparam BGDef bg Background definition userdata.
-- @tparam[opt] int32 layer `0` for back layer, `1` for front layer.
-- @tparam[opt] float32 x Global X offset applied when drawing.
-- @tparam[opt] float32 y Global Y offset applied when drawing.
-- @tparam[opt=1.0] float32 scale Uniform global scale multiplier.
function bgDraw(bg, layer, x, y, scale) end

--- Load a background definition from a sprite file and configuration.
-- @function bgNew
-- @tparam Sff sff Sprite file userdata used by the background.
-- @tparam string defPath Path used for resolving background resources.
-- @tparam string section Name or identifier of the background definition to load.
-- @tparam Model model Stage/model userdata associated with this background.
-- @tparam[opt=0] int32 defaultLayer Default layer index assigned to the background elements.
-- @treturn BGDef bg Loaded background definition userdata.
function bgNew(sff, defPath, section, model, defaultLayer) end

--- Reset a background definition to its initial state.
-- @function bgReset
-- @tparam BGDef bg Background definition userdata.
function bgReset(bg) end

--- Change the current animation of the debug watch character. [redirectable]
-- @function changeAnim
-- @tparam int32 animNo Animation number to switch to.
-- @tparam[opt] int32 elem Optional animation element index to start from.
-- @tparam[opt=false] boolean ffx If `true`, use the `"f"` animation prefix (FFX animation).
-- @treturn boolean success `true` if the animation exists and was changed, `false` otherwise.
function changeAnim(animNo, elem, ffx) end

--- Validate a requested palette index for a character.
-- @function validatePal
-- @tparam int32 palReq Requested palette number (1-based).
-- @tparam int32 charRef Character slot index in the select definition (1-based).
-- @treturn int32 validPal Engine-validated palette number (may differ from `palReq`
--   depending on character configuration).
function validatePal(palReq, charRef) end

--- Change the active palette mapping for an animation.
-- @function changeColorPalette
-- @tparam Anim anim Animation userdata.
-- @tparam int32 paletteId 1-based palette identifier to map to.
-- @treturn Anim anim The same animation userdata (for chaining).
function changeColorPalette(anim, paletteId) end

--- Change the current state of the debug watch character, or disable it. [redirectable]
-- @function changeState
-- @tparam int32 stateNo State number to switch to, or `-1` to disable the character.
-- @treturn boolean success `true` if the state exists and was changed, `false` otherwise.
function changeState(stateNo) end

--- Clear all characters' clipboard text buffers.
-- @function clear
function clear() end

--- Stop all currently playing sounds.
-- @function clearAllSound
function clearAllSound() end

--- Fill the screen with a solid color (with optional alpha).
-- @function clearColor
-- @tparam int32 r Red component (0–255).
-- @tparam int32 g Green component (0–255).
-- @tparam int32 b Blue component (0–255).
-- @tparam[opt=255] int32 alpha Alpha value (0–255); `255` is fully opaque.
function clearColor(r, g, b, alpha) end

--- Clear text printed to the in-engine console.
-- @function clearConsole
function clearConsole() end

--- Clear all current select-screen choices (characters, stages, etc.).
-- @function clearSelected
function clearSelected() end

--- Add a command definition to a command list.
-- @function commandAdd
-- @tparam CommandList cmdList Command list userdata.
-- @tparam string name Command name (used in triggers).
-- @tparam string command Command string in engine input notation.
-- @tparam[opt] int32 time Command input time window in ticks (defaults to `cmdList.DefaultTime`).
-- @tparam[opt] int32 bufferTime Buffer time in ticks (defaults to `cmdList.DefaultBufferTime`).
-- @tparam[opt] boolean bufferHitpause Whether inputs are buffered during hitpause
--   (defaults to `cmdList.DefaultBufferHitpause`).
-- @tparam[opt] boolean bufferPauseend Whether inputs are buffered during pause end
--   (defaults to `cmdList.DefaultBufferPauseEnd`).
-- @tparam[opt] int32 stepTime Step granularity in ticks (defaults to `cmdList.DefaultStepTime`).
function commandAdd(cmdList, name, command, time, bufferTime, bufferHitpause, bufferPauseend, stepTime) end

--- Reset the internal input buffer of a command list.
-- @function commandBufReset
-- @tparam CommandList cmdList Command list userdata.
function commandBufReset(cmdList) end

--- Query the current state of a named command.
-- @function commandGetState
-- @tparam CommandList cmdList Command list userdata.
-- @tparam string name Command name to query.
-- @treturn boolean active `true` if the command is currently active, `false` otherwise.
function commandGetState(cmdList, name) end

--- Feed input into a command list from a controller for this frame.
-- @function commandInput
-- @tparam CommandList cmdList Command list userdata.
-- @tparam int32 controller Controller index (1-based).
function commandInput(cmdList, controller) end

--- Create a new command list bound to an input buffer.
-- @function commandNew
-- @tparam[opt] int32 controllerNo Controller index (1-based). If greater than `0`,
--   the new list is stored in `sys.commandLists[controllerNo]`.
-- @treturn CommandList cmdList Newly created command list userdata.
function commandNew(controllerNo) end

--- Compute and store ranking data for a mode, returning whether it was cleared.
-- @function computeRanking
-- @tparam string mode Ranking mode identifier.
-- @treturn boolean cleared `true` if the run cleared the mode's requirements.
-- @treturn int32 place Ranking position (1-based) or engine-defined value.
function computeRanking(mode) end

--- Check if the main menu network connection is established.
-- @function connected
-- @treturn boolean connected `true` if connected to a netplay peer, `false` otherwise.
function connected() end

--- Signal that the current match should end (using menu fade-out settings).
-- @function endMatch
function endMatch() end

--- Enter netplay as client or host.
-- @function enterNetPlay
-- @tparam string host Host address (IP or hostname). If an empty string, listen
--   for an incoming connection; otherwise connect to the given host.
function enterNetPlay(host) end

--- Enter replay playback mode from a replay file.
-- @function enterReplay
-- @tparam string path Path to the replay file.
function enterReplay(path) end

--- Get or set the global escape flag.
-- @function esc
-- @tparam[opt] boolean value If provided, sets the escape flag.
-- @treturn boolean esc Current value of the escape flag.
function esc(value) end

--- Exit netplay mode and close any active netplay connection.
-- @function exitNetPlay
function exitNetPlay() end

--- Exit replay mode and restore normal video settings.
-- @function exitReplay
function exitReplay() end

---NOTE: currently unused in Lua (commented out)
--- Check whether the global fade-in effect is active.
-- @function fadeInActive
-- @treturn boolean active `true` if a fade-in is currently running.
function fadeInActive() end

---NOTE: currently unused in Lua (commented out)
--- Initialize the global fade-in effect using motif settings.
-- @function fadeInInit
-- @tparam Fade fade Fade userdata to initialize.
function fadeInInit(fade) end

---NOTE: currently unused in Lua (commented out)
--- Check whether the global fade-out effect is active.
-- @function fadeOutActive
-- @treturn boolean active `true` if a fade-out is currently running.
function fadeOutActive() end

---NOTE: currently unused in Lua (commented out)
--- Initialize the global fade-out effect using motif settings.
-- @function fadeOutInit
-- @tparam Fade fade Fade userdata to initialize.
function fadeOutInit(fade) end

--- Test whether a file exists, after engine path resolution.
-- @function fileExists
-- @tparam string path File path to test (relative or absolute).
-- @treturn boolean exists `true` if the file exists, `false` otherwise.
function fileExists(path) end

--- Find the next entity with the given player ID and focus it in debug watch.
-- @function findEntityByPlayerId
-- @tparam int32 playerId Target entity `id` to search for.
-- @raise Raises an error if no entity with the given `playerId` is found.
-- @see findEntityByName
-- @see findHelperById
function findEntityByPlayerId(playerId) end

--- Find the next entity whose name contains the given text and focus it in debug watch.
-- @function findEntityByName
-- @tparam string text Case-insensitive substring to search in entity names.
-- @raise Raises an error if no entity name contains the given text.
-- @see findEntityByPlayerId
-- @see findHelperById
function findEntityByName(text) end

--- Find the next helper with the given helper ID and focus it in debug watch.
-- @function findHelperById
-- @tparam int32 helperId Target helper `helperId` to search for.
-- @raise Raises an error if no helper with the given `helperId` is found.
-- @see findEntityByPlayerId
-- @see findEntityByName
function findHelperById(helperId) end

--- Get basic font definition information.
-- @function fontGetDef
-- @tparam Fnt font Font userdata.
-- @treturn table def A table:
--   - `Type` (string) font type identifier  
--   - `Size` (int32[2]) `{width, height}` in pixels  
--   - `Spacing` (int32[2]) `{x, y}` spacing in pixels  
--   - `offset` (int32[2]) `{x, y}` base drawing offset  
function fontGetDef(font) end

--- Load a font from file.
-- @function fontNew
-- @tparam string filename Font filename (searched in `font/`, motif folder, current dir, `data/`).
-- @tparam[opt=-1] int32 height Override font height; `-1` uses the height defined in the font file.
-- @treturn Fnt font Loaded font userdata. If loading fails, a fallback font is returned.
function fontNew(filename, height) end

--- Execute a full match using the current configuration.
-- @function game
-- @treturn int32 winSide Winning side index (`1` or `2`), `0` for draw, `-1` if the game was ended externally.
-- @treturn int32 controllerNo Controller index (1-based) used for post-match menu control.
function game() end

--- Resolve and read basic information from a character definition file.
-- @function getCharAttachedInfo
-- @tparam string def Character identifier or `.def` path. If no extension is given,
--   `"chars/<def>/<def>.def"` is assumed.
-- @treturn[1] table info A table:
--   - `name` (string) character display name (or internal name as fallback)  
--   - `def` (string) resolved `.def` path  
--   - `sound` (string) sound file path from the `[Files]` section  
-- @treturn[0] nil If the `.def` file cannot be resolved.
function getCharAttachedInfo(def) end

--- Get the definition file path for a character slot.
-- @function getCharFileName
-- @tparam int32 charRef Character slot index in the select definition (1-based).
-- @treturn string defPath Resolved `.def` path for this slot.
function getCharFileName(charRef) end

--- Get detailed information about a character slot.
-- @function getCharInfo
-- @tparam int32 charRef Character slot index in the select definition (1-based).
-- @treturn table info A table:
--   - `name` (string) character display name  
--   - `author` (string) author string  
--   - `def` (string) definition file path  
--   - `sound` (string) sound file path  
--   - `intro` (string) intro def path  
--   - `ending` (string) ending def path  
--   - `arcadepath` (string) arcade path override  
--   - `ratiopath` (string) ratio path override  
--   - `localcoord` (int32) base localcoord width  
--   - `portraitscale` (float32) scale applied to portraits  
--   - `cns_scale` (float32[]) scale values from the CNS configuration  
--   - `pal` (int32[]) available palette numbers (at least `{1}`)  
--   - `pal_defaults` (int32[]) default palette numbers (at least `{1}`)  
--   - `pal_keymap` (table) palette key remaps, indexed by original palette slot  
function getCharInfo(charRef) end

--- Get the movelist file path for a character slot.
-- @function getCharMovelist
-- @tparam int32 charRef Character slot index in the select definition (1-based).
-- @treturn string movelist Path or identifier of the movelist file.
function getCharMovelist(charRef) end

--- Get the display name of a character slot.
-- @function getCharName
-- @tparam int32 charRef Character slot index in the select definition (1-based).
-- @treturn string name Character display name.
function getCharName(charRef) end

--- Get a random valid palette number for a character slot.
-- @function getCharRandomPalette
-- @tparam int32 charRef Character slot index in the select definition (1-based).
-- @treturn int32 palNo Palette number; defaults to `1` if the character has no palette list.
function getCharRandomPalette(charRef) end

--- Get the parsed select parameters for a character entry.
-- This returns the Lua table created from the comma-separated `params` string passed to `addChar()`
-- @function getCharSelectParams
-- @tparam number index Character entry index to read (starting from 0).
-- @treturn table params Table of parsed parameters for that character entry.
function getCharSelectParams(index) end

--- Get the current system clipboard string.
-- @function getClipboardString
-- @treturn string text Clipboard contents, or an empty string if unavailable.
function getClipboardString() end

--- Get all command-line flags passed to the engine.
-- @function getCommandLineFlags
-- @treturn table flags A table mapping flag names (string) to their values (string).
function getCommandLineFlags() end

--- Get the value of a specific command-line flag.
-- @function getCommandLineValue
-- @tparam string flagName Flag name (without leading dashes).
-- @treturn[1] string value Value associated with the flag.
-- @treturn[0] nil If the flag is not present.
function getCommandLineValue(flagName) end

--- Get the number of consecutive wins for a team.
-- @function getConsecutiveWins
-- @tparam int32 teamSide Team side (`1` or `2`).
-- @treturn int32 wins Number of consecutive wins for the given side.
function getConsecutiveWins(teamSide) end

--- Recursively list all files under a directory.
-- @function getDirectoryFiles
-- @tparam string rootPath Starting directory path.
-- @treturn table files Array-like table of file paths (string).
function getDirectoryFiles(rootPath) end

--- Get the global frame counter value.
-- @function getFrameCount
-- @treturn int32 frameCount Number of frames elapsed since engine start.
function getFrameCount() end

--- Get a joystick's GUID string.
-- @function getJoystickGUID
-- @tparam int32 index Joystick index (0-based).
-- @treturn string guid GUID string for the joystick, or an empty string if invalid.
function getJoystickGUID(index) end

--- Get a joystick's display name.
-- @function getJoystickName
-- @tparam int32 index Joystick index (0-based).
-- @treturn string name Human-readable joystick name, or an empty string if invalid.
function getJoystickName(index) end

--- Check whether a joystick is present.
-- @function getJoystickPresent
-- @tparam int32 index Joystick index (0-based).
-- @treturn boolean present `true` if the joystick is connected, `false` otherwise.
function getJoystickPresent(index) end

--- Wait for a joystick input and return the corresponding key string.
-- @function getJoystickKey
-- @tparam[opt=-1] int32 controllerIdx Joystick index (0-based), or `-1` to listen on any joystick.
-- @treturn string keyName Engine key string for the pressed control (empty string if none).
-- @treturn int32 joystickIndex 1-based joystick index that generated the input; `-1` if no input.
function getJoystickKey(controllerIdx) end

--- Query or compare the last pressed key.
-- @function getKey
-- @tparam[opt] string key If omitted, the last key name is returned. If a non-empty string
--   is given, returns whether it matches the last key. If an empty string is given,
--   always returns `false`.
-- @treturn[1] string keyName Last key name (when called with no arguments).
-- @treturn[2] boolean pressed `true` if the last key equals `key` (when `key` is non-empty).
function getKey(key) end

--- Get the last input text associated with the current key event.
-- @function getKeyText
-- @treturn string text If the last key was Insert, returns the clipboard contents,
--   otherwise returns the textual representation of the last key press. Empty string if none.
function getKeyText() end

--- Get the parsed launch-fight parameters used by the current/next game sequence.
-- This returns the Lua table created from the comma-separated `params` string passed to `loadStart()`
-- @function getLaunchFightParams
-- @treturn table params Table of parsed parameters for the game.
function getLaunchFightParams() end

--- Get the maximum number of draw games allowed for a team.
-- @function getMatchMaxDrawGames
-- @tparam int32 teamSide Team side (`1` or `2`).
-- @treturn int32 maxDrawGames Maximum draw games before the match is decided.
function getMatchMaxDrawGames(teamSide) end

--- Get the number of match wins required for a team.
-- @function getMatchWins
-- @tparam int32 teamSide Team side (`1` or `2`).
-- @treturn int32 wins Number of wins required to win the match.
function getMatchWins(teamSide) end

--- Get the configured round time limit.
-- @function getRoundTime
-- @treturn int32 time Round time limit in ticks (or special values as configured).
function getRoundTime() end

--- Get information about a stage slot.
-- @function getStageInfo
-- @tparam int32 stageRef Stage slot index in the select definition (1-based).
-- @treturn table info A table:
--   - `name` (string) stage display name  
--   - `def` (string) definition file path  
--   - `localcoord` (int32) base localcoord width  
--   - `portraitscale` (float32) scale applied to stage portraits  
--   - `attachedchardef` (string[]) list of attached character `.def` paths  
function getStageInfo(stageRef) end

--- Get the currently selected stage slot index.
-- @function getStageNo
-- @treturn int32 stageRef Currently selected stage slot index (1-based).
function getStageNo() end

--- Get the parsed select parameters for a stage entry.
-- This returns the Lua table created from the comma-separated `params` string passed to `addStage()`
-- @function getStageSelectParams
-- @tparam number index Stage entry index to read (starting from 1).
-- @treturn table params Table of parsed parameters for that stage entry.
function getStageSelectParams(index) end

--- Get a formatted timestamp string.
-- @function getTimestamp
-- @tparam[opt="2006-01-02 15:04:05.000"] string format Go-style time format layout.
-- @treturn string timestamp Current time formatted according to `format`.
function getTimestamp(format) end

--- Load raw wave data from a sound file or SND group/sound pair.
-- @function getWaveData
-- @tparam string path Path to the sound file or SND container.
-- @tparam int32 group Group number in the SND.
-- @tparam int32 sound Sound number in the SND.
-- @tparam[opt] uint32 maxLoops Maximum group/sound loops to search before giving up.
-- @treturn Wave wave Wave userdata containing the loaded sound data.
function getWaveData(path, group, sound, maxLoops) end

--- Decode a JSON file into Lua values.
-- @function jsonDecode
-- @tparam string path Path to the JSON file.
-- @treturn any value Decoded JSON root value (Lua `string`, `number`, `boolean`, `table` or `nil`).
function jsonDecode(path) end

--- Encode a Lua value to JSON and save it to a file.
-- @function jsonEncode
-- @tparam any value Lua value to encode (tables, numbers, strings, booleans, or `nil`).
-- @tparam string path Output JSON file path (parent directories are created as needed).
function jsonEncode(value, path) end

--- Request loading of a previously saved state on the next frame.
-- @function loadState
function loadState() end

--- Load and set the font used by the debug overlay.
-- @function loadDebugFont
-- @tparam string filename Font filename.
-- @tparam[opt] float32 scale Uniform scale applied to debug text (both X and Y).
function loadDebugFont(filename, scale) end

--- Register Lua functions to be called for debug info display.
-- @function loadDebugInfo
-- @tparam table funcs Array-like table of global function names (string).
function loadDebugInfo(funcs) end

--- Register the Lua function used to draw debug status.
-- @function loadDebugStatus
-- @tparam string funcName Global Lua function name used for debug status.
function loadDebugStatus(funcName) end

--- Load game options from a config file and return the current config as a table.
-- @function loadGameOption
-- @tparam[opt] string filename Config file path. If omitted, current config is kept.
-- @treturn table cfg Table representation of the current game configuration.
function loadGameOption(filename) end

--- Check whether resources are currently being loaded.
-- @function loading
-- @treturn boolean loading `true` if the loader is in `LS_Loading` state.
function loading() end

--- Load an AIR/animation definition file and return an animation table.
-- @function loadAnimTable
-- @tparam string path Animation file path (typically a .air file).
-- @tparam[opt] Sff sff Sprite file userdata used to resolve sprites while parsing.
--   If omitted or invalid, an empty SFF is created internally.
-- @treturn table animTable Table mapping action numbers (int32) to `Animation` userdata.
--   Each value is a parsed `*Animation` (usable with `animNew` and `animSetAnimation`).
function loadAnimTable(path, sff) end

--- Load an INI file and convert it to a nested Lua table.
-- @function loadIni
-- @tparam string filename INI file path.
-- @treturn table ini Table of sections; each section is a table of keys to strings.
--   Dotted keys are converted to nested subtables.
function loadIni(filename) end

--- Load the lifebar definition.
-- @function loadLifebar
-- @tparam[opt] string defPath Lifebar def file path. If empty or omitted, uses default.
function loadLifebar(defPath) end

--- Load a motif and return its configuration as a table.
-- @function loadMotif
-- @tparam[opt] string defPath Motif def file path. If empty or omitted, uses default.
-- @treturn table motif Motif configuration table (includes menus, fonts, sounds, etc.).
function loadMotif(defPath) end

--- Validate selection and start asynchronous loading of characters and stage.
-- @function loadStart
-- @tparam[opt] string params Optional comma-separated parameter string (from launchFight and quickvs options)
function loadStart(params) end

--- Load a text file and return its contents.
-- @function loadText
-- @tparam string path Text file path.
-- @treturn[1] string content File contents on success.
-- @treturn[0] nil If the file cannot be read.
function loadText(path) end

--- Load a storyboard and set it as the current storyboard.
-- @function loadStoryboard
-- @tparam string defPath Storyboard def file path.
-- @treturn[1] table storyboard Storyboard configuration table on success.
-- @treturn[0] nil If no path is given or loading fails (a warning is printed).
function loadStoryboard(defPath) end

--- Modify a game option using a query string path.
-- @function modifyGameOption
-- @tparam string query Option path in config (for example `"GameSpeed.Value"`).
-- @tparam any value New value:
--   - `boolean`: stored as boolean  
--   - `nil`: remove/clear value depending on context  
--   - `table`: treated as array of strings  
--   - other: converted to string  
-- @raise Raises an error if the query is invalid or cannot be applied.
function modifyGameOption(query, value) end

--- Modify a motif using a query string path.
-- @function modifyMotif
-- @tparam string query Parameter path in motif (for example `"attract_mode.credits.snd"`).
-- @tparam any value New value:
--   - `boolean`: stored as boolean  
--   - `nil`: remove/clear value depending on context  
--   - `table`: treated as array of strings  
--   - other: converted to string  
-- @raise Raises an error if the query is invalid or cannot be applied.
function modifyMotif(query, value) end

--- Modify a currently loaded storyboard using a query string path.
-- @function modifyStoryboard
-- @tparam string query Parameter path in storyboard (for example `"scenedef.stopmusic"`).
-- @tparam any value New value:
--   - `boolean`: stored as boolean  
--   - `nil`: remove/clear value depending on context  
--   - `table`: treated as array of strings  
--   - other: converted to string  
-- @raise Raises an error if the query is invalid or cannot be applied.
function modifyStoryboard(query, value) end

--- [redirectable] Set a debug watch character map value.
-- @function mapSet
-- @tparam string name Map name to modify.
-- @tparam float32 value Map value to set.
-- @tparam[opt] string mapType Map operation type. `"add"` adds to the existing value,
--   anything else replaces it.
function mapSet(name, value, mapType) end

--- Raise an immediate Lua error with a custom message.
-- @function panicError
-- @tparam string message Error message.
function panicError(message) end

--- [redirectable] Control background music playback.
-- @function playBgm
-- @tparam table params Parameter table (keys are case-insensitive):
--   - `source` (string, opt) preset to use, formatted as `"<origin>.<key>"`  
--      - `origin` = `"stagedef"`, `"stageparams"`, `"launchparams"`, `"motif"`, `"match"`, `"charparams"`  
--      - `key` is origin-specific (for example `"bgm"`, `"win"` etc.)  
--   - `bgm` (string, opt) BGM filename; searched in stage and `sound/` folders  
--   - `loop` (int32, opt) Loop flag/mode (see engine BGM semantics)  
--   - `volume` (int32, opt) BGM volume (0–100, clamped to config MaxBGMVolume)  
--   - `loopstart` (int32, opt) Loop start position (samples/frames, engine-specific)  
--   - `loopend` (int32, opt) Loop end position  
--   - `startposition` (int32, opt) Initial playback position  
--   - `freqmul` (float32, opt) Frequency multiplier (pitch)  
--   - `loopcount` (int32, opt) Loop count (`-1` for infinite)  
--   - `interrupt` (boolean, opt) If `true`, always restart playback; if `false`, only update volume;  
--     if omitted, interruption is decided automatically based on whether the file changed.  
function playBgm(params) end

--- [redirectable] Play a sound associated with the debug watch character.
-- @function playSnd
-- @tparam[opt=-1] int32 group Sound group number. `-1` means no group.
-- @tparam[opt=0] int32 sound Sound number within the group.
-- @tparam[opt=100] int32 volumescale Volume scale (percent).
-- @tparam[opt=false] boolean commonSnd If `true`, play from common SND (prefix `"f"`).
-- @tparam[opt=-1] int32 channel Sound channel (`-1` = auto).
-- @tparam[opt=false] boolean lowpriority If `true`, sound can be overridden by higher-priority sounds.
-- @tparam[opt=1.0] float32 freqmul Frequency multiplier (pitch).
-- @tparam[opt=false] boolean loop If `true`, sound loops (ignored if `loopcount` is non-zero).
-- @tparam[opt=0.0] float32 pan Stereo panning (engine-specific range, usually -1.0 to 1.0).
-- @tparam[opt=0] int32 priority Priority level (higher plays over lower).
-- @tparam[opt=0] int loopstart Loop start position.
-- @tparam[opt=0] int loopend Loop end position.
-- @tparam[opt=0] int startposition Initial playback position.
-- @tparam[opt=0] int32 loopcount Loop count: `0` uses `loop` flag, positive = exact loops, negative = infinite.
-- @tparam[opt=false] boolean stopOnGetHit If `true`, stop this sound when the character is hit.
-- @tparam[opt=false] boolean stopOnChangeState If `true`, stop this sound when the character changes state.
function playSnd(group, sound, volumescale, commonSnd, channel, lowpriority, freqmul,
                 loop, pan, priority, loopstart, loopend, startposition, loopcount,
                 stopOnGetHit, stopOnChangeState) end

--- Reset player input buffers and disable hardcoded keys.
-- @function playerBufReset
-- @tparam[opt] int32 playerNo Player index (1-based). If omitted, resets all players.
function playerBufReset(playerNo) end

--- Mark a character sprite or animation for preloading.
-- @function preloadListChar
-- @tparam int32 id Action number or group number.
-- @tparam[opt] int32 number If provided, `id` is treated as sprite group and this as sprite number;
--   otherwise `id` is treated as an animation/action number.
function preloadListChar(id, number) end

--- Mark a stage sprite or animation for preloading.
-- @function preloadListStage
-- @tparam int32 id Action number or group number.
-- @tparam[opt] int32 number If provided, `id` is treated as sprite group and this as sprite number;
--   otherwise `id` is treated as an animation/action number.
function preloadListStage(id, number) end

--- Print text to the in-game console and standard output.
-- @function printConsole
-- @tparam string text Text to print.
-- @tparam[opt=false] boolean appendLast If `true`, appends to the last console line; otherwise starts a new line.
function printConsole(text, appendLast) end

--- Print text to standard output (stdout) only.
-- @function puts
-- @tparam string text Text to print.
function puts(text) end

--- Read accumulated game statistics.
-- @function readGameStats
-- @treturn table stats Statistics log object as a Lua table.
function readGameStats() end

--- Advance one frame: process logic, drawing and fades.
-- @function refresh
-- @raise Raises `<game end>` when the game loop has ended.
function refresh() end

--- Print a rectangle's debug information.
-- @function rectDebug
-- @tparam Rect rect Rectangle userdata.
-- @tparam[opt] string prefix Optional text printed before the rectangle.
function rectDebug(rect, prefix) end

--- Queue drawing of a rectangle.
-- @function rectDraw
-- @tparam Rect rect Rectangle userdata.
-- @tparam[opt] int16 layer Layer number to draw on (defaults to `rect.layerno`).
function rectDraw(rect, layer) end

--- Create a new rectangle object.
-- @function rectNew
-- @treturn Rect rect Newly created rectangle userdata.
function rectNew() end

--- Reset rectangle parameters to defaults.
-- @function rectReset
-- @tparam Rect rect Rectangle userdata.
function rectReset(rect) end

--- Set rectangle RGB color.
-- @function rectSetColor
-- @tparam Rect rect Rectangle userdata.
-- @tparam int32 r Red component (0–255).
-- @tparam int32 g Green component (0–255).
-- @tparam int32 b Blue component (0–255).
function rectSetColor(rect, r, g, b) end

--- Set rectangle alpha blending values.
-- @function rectSetAlpha
-- @tparam Rect rect Rectangle userdata.
-- @tparam int32 src Source alpha.
-- @tparam int32 dst Destination alpha.
function rectSetAlpha(rect, src, dst) end

--- Enable pulsing alpha effect for a rectangle.
-- @function rectSetAlphaPulse
-- @tparam Rect rect Rectangle userdata.
-- @tparam int32 min Minimum alpha.
-- @tparam int32 max Maximum alpha.
-- @tparam int32 time Pulse period (frames).
function rectSetAlphaPulse(rect, min, max, time) end

--- Set the rectangle's drawing layer.
-- @function rectSetLayerno
-- @tparam Rect rect Rectangle userdata.
-- @tparam int16 layer Layer number.
function rectSetLayerno(rect, layer) end

--- Set the rectangle's local coordinate system.
-- @function rectSetLocalcoord
-- @tparam Rect rect Rectangle userdata.
-- @tparam float32 x Local coordinate width.
-- @tparam float32 y Local coordinate height.
function rectSetLocalcoord(rect, x, y) end

--- Set the rectangle's clipping window.
-- @function rectSetWindow
-- @tparam Rect rect Rectangle userdata.
-- @tparam float32 x1 Left coordinate.
-- @tparam float32 y1 Top coordinate.
-- @tparam float32 x2 Right coordinate.
-- @tparam float32 y2 Bottom coordinate.
function rectSetWindow(rect, x1, y1, x2, y2) end

--- Update rectangle animation (alpha pulse, etc.).
-- @function rectUpdate
-- @tparam Rect rect Rectangle userdata.
function rectUpdate(rect) end

--- Schedule reloading of characters, stage and lifebar.
-- @function reload
function reload() end

--- Remap logical player input to another player slot.
-- @function remapInput
-- @tparam int32 srcPlayer Source player number (1-based).
-- @tparam int32 dstPlayer Destination player number (1-based).
function remapInput(srcPlayer, dstPlayer) end

--- [redirectable] Clear the debug watch character's dizzy state.
-- @function removeDizzy
function removeDizzy() end

--- Start recording rollback/netplay input to a file.
-- @function replayRecord
-- @tparam string path Output file path.
function replayRecord(path) end

--- Stop input replay recording.
-- @function replayStop
function replayStop() end

--- Clear the last captured key and text input.
-- @function resetKey
function resetKey() end

--- Reset AI level for all players to 0 (human control).
-- @function resetAILevel
function resetAILevel() end

--- Reset match-related runtime data.
-- @function resetMatchData
-- @tparam boolean fullReset If `true`, perform a full match data reset.
function resetMatchData(fullReset) end

--- Reset all input remapping to defaults.
-- @function resetRemapInput
function resetRemapInput() end

--- Reset a team's score to zero.
-- @function resetScore
-- @tparam int32 teamSide Team side (`1` or `2`).
function resetScore(teamSide) end

--- Clear all accumulated game statistics.
-- @function resetGameStats
function resetGameStats() end

--- Request a round reset.
-- @function roundReset
function roundReset() end

--- Run the currently loaded storyboard for one frame.
-- @function runStoryboard
-- @treturn boolean active `true` while the storyboard is active.
function runStoryboard() end

--- Run the high-score screen for one frame.
-- @function runHiscore
-- @tparam[opt] string mode Optional hiscore mode identifier.
-- @tparam[opt] int32 place Optional ranking position to highlight.
-- @tparam[opt] int32 endtime Optional override for the hiscore screen duration.
-- @tparam[opt] bool nofade Optional flag to disable fade-in and fade-out effects.
-- @tparam[opt] bool nofade Optional flag to disable background rendering.
-- @treturn boolean active `true` while the hiscore screen is active.
function runHiscore(mode, place, endtime, nofade, nobgs) end

--- Request saving of the current state on the next frame.
-- @function saveState
function saveState() end

--- Save current game options to file.
-- @function saveGameOption
-- @tparam[opt] string path Config file path. Defaults to the current config's `Def` path.
function saveGameOption(path) end

--- Take a screenshot on the next frame.
-- @function screenshot
function screenshot() end

--- Search for a file in a list of directories.
-- @function searchFile
-- @tparam string filename Filename to search for.
-- @tparam table dirs Array-like table of directory paths (string).
-- @treturn string path Resolved file path, or empty string if not found.
function searchFile(filename, dirs) end

--- Add a character to a team's selection.
-- @function selectChar
-- @tparam int32 teamSide Team side (`1` or `2`).
-- @tparam int32 charRef Character index in the select list.
-- @tparam int32 palette Palette number.
-- @treturn int32 status Selection status:
--   - `0` – character not added  
--   - `1` – added, team is not yet full  
--   - `2` – added, team is now full
function selectChar(teamSide, charRef, palette) end

--- Select a stage by index.
-- @function selectStage
-- @tparam int32 stageRef Stage index in the stage list.
function selectStage(stageRef) end

--- Clear current selection and start loading the match.
-- @function selectStart
function selectStart() end

--- Load an SFF file or create an empty SFF.
-- @function sffNew
-- @tparam[opt] string filename SFF file path. If omitted, an empty SFF is created.
-- @tparam[opt] bool. If true. Prepares SFFv1 to receive ACT Palettes. If omitted defaults to false.
-- @treturn Sff sff SFF userdata.
function sffNew(filename) end

--- Load a 3D model (glTF) as a Model object.
-- @function modelNew
-- @tparam string filename glTF model file path.
-- @treturn Model model Model userdata.
function modelNew(filename) end

--- [redirectable] Force the debug watch character into a specified state.
-- @function selfState
-- @tparam int32 stateNo Target state number.
function selfState(stateNo) end

--- Set debug time acceleration.
-- @function setAccel
-- @tparam float32 accel Time acceleration multiplier.
function setAccel(accel) end

--- [redirectable] Set AI level for the debug watch character's side.
-- @function setAILevel
-- @tparam float32 level AI level (`0` = human control, >0 = AI).
function setAILevel(level) end

--- Set AI level for a specific player.
-- @function setCom
-- @tparam int32 playerNo Player number (1-based).
-- @tparam float32 level AI level (`0` = off, >0 = AI).
function setCom(playerNo, level) end

--- Set the number of consecutive wins for a team.
-- @function setConsecutiveWins
-- @tparam int32 teamSide Team side (`1` or `2`).
-- @tparam int32 wins Number of consecutive wins.
function setConsecutiveWins(teamSide, wins) end

--- Set the number of credits.
-- @function setCredits
-- @tparam int32 credits Credit count.
function setCredits(credits) end

--- [redirectable] Set the debug watch character's dizzy points.
-- @function setDizzyPoints
-- @tparam int32 value Dizzy points value.
function setDizzyPoints(value) end

--- Set current game mode identifier.
-- @function setGameMode
-- @tparam string mode Game mode name (for example `"arcade"`, `"versus"`, `"training"`).
function setGameMode(mode) end

--- [redirectable] Set the debug watch character's guard points.
-- @function setGuardPoints
-- @tparam int32 value Guard points value.
function setGuardPoints(value) end

--- Set which team is the home team.
-- @function setHomeTeam
-- @tparam int32 teamSide Team side (`1` or `2`).
function setHomeTeam(teamSide) end

--- Configure keyboard or joystick bindings for a player.
-- @function setKeyConfig
-- @tparam int32 playerNo Player number (1-based).
-- @tparam int32 controllerId Controller index (`-1` for keyboard, `0+` for joystick index).
-- @tparam table mapping Table mapping button indices (1–14) to key/button names (string).
function setKeyConfig(playerNo, controllerId, mapping) end

--- [redirectable] Set the debug watch character's life.
-- @function setLife
-- @tparam int32 life New life value (only applied if the character is alive).
function setLife(life) end

--- Force enable/disable of lifebar elements.
-- @function setLifebarElements
-- @tparam table elements Table of boolean flags (keys are case-insensitive):
--   - `active` (boolean) enable lifebar drawing  
--   - `bars` (boolean) main life bars  
--   - `guardbar` (boolean) guard bar  
--   - `hidebars` (boolean) hide bars during dialogue  
--   - `match` (boolean) match info  
--   - `mode` (boolean) mode display  
--   - `p1ailevel`, `p2ailevel` (boolean) AI level displays  
--   - `p1score`, `p2score` (boolean) score displays  
--   - `p1wincount`, `p2wincount` (boolean) win count displays  
--   - `redlifebar` (boolean) red life bar  
--   - `stunbar` (boolean) stun bar  
--   - `timer` (boolean) round timer
function setLifebarElements(elements) end

--- Set initial lifebar scores for both teams.
-- @function setLifebarScore
-- @tparam float32 p1Score Starting score for team 1.
-- @tparam[opt] float32 p2Score Starting score for team 2 (defaults to 0 if omitted).
function setLifebarScore(p1Score, p2Score) end

--- Set initial round timer value displayed on the lifebar.
-- @function setLifebarTimer
-- @tparam int32 time Initial timer value.
function setLifebarTimer(time) end

--- Set maximum number of draw games allowed for a team.
-- @function setMatchMaxDrawGames
-- @tparam int32 teamSide Team side (`1` or `2`).
-- @tparam int32 count Maximum draw games.
function setMatchMaxDrawGames(teamSide, count) end

--- Set the current match number.
-- @function setMatchNo
-- @tparam int32 matchNo Match index/number.
function setMatchNo(matchNo) end

--- Set number of round wins required to win the match for a team.
-- @function setMatchWins
-- @tparam int32 teamSide Team side (`1` or `2`).
-- @tparam int32 wins Required wins.
function setMatchWins(teamSide, wins) end

--- Enable/disable major motif elements.
-- @function setMotifElements
-- @tparam table elements Table of boolean flags (keys are case-insensitive):
--   - `challenger` (boolean) challenger screen  
--   - `continuescreen` (boolean) continue screen  
--   - `demo` (boolean) demo/attract mode  
--   - `dialogue` (boolean) dialogue system  
--   - `hiscore` (boolean) hiscore screen  
--   - `losescreen` (boolean) lose screen  
--   - `versusscreen` (boolean) versus screen  
--   - `versusmatchno` (boolean) versus screen match number  
--   - `victoryscreen` (boolean) victory screen  
--   - `winscreen` (boolean) win screen  
--   - `menu` (boolean) main menu
function setMotifElements(elements) end

--- Set the total number of supported players and resize input configs.
-- @function setPlayers
-- @tparam int32 total Number of players.
function setPlayers(total) end

--- [redirectable] Set the debug watch character's power.
-- @function setPower
-- @tparam int32 power Power value.
function setPower(power) end

--- [redirectable] Set the debug watch character's red life.
-- @function setRedLife
-- @tparam int32 value Red life value.
function setRedLife(value) end

--- Set global game speed option.
-- @function setGameSpeed
-- @tparam int32 speed Game speed value (engine-specific range).
function setGameSpeed(speed) end

--- Set maximum round time (in ticks/counts).
-- @function setRoundTime
-- @tparam int32 time Maximum round time.
function setRoundTime(time) end

--- Enable or disable consecutive rounds mode.
-- @function setConsecutiveRounds
-- @tparam boolean enabled If `true`, consecutive rounds are enabled.
function setConsecutiveRounds(enabled) end

--- Configure a team's mode and team size.
-- @function setTeamMode
-- @tparam int32 teamSide Team side (`1` or `2`).
-- @tparam int32 mode Team mode (for example `TM_Single`, `TM_Simul`, `TM_Turns`, `TM_Tag`).
-- @tparam int32 teamSize Number of members (for non-turns: `1..MaxSimul`, for turns: `>=1`).
function setTeamMode(teamSide, mode, teamSize) end

--- Set the current round time value.
-- @function setTime
-- @tparam int32 time Current timer value.
function setTime(time) end

--- Set how many frames correspond to one timer count.
-- @function setTimeFramesPerCount
-- @tparam int32 frames Frames per timer count.
function setTimeFramesPerCount(frames) end

--- Set win count for a team.
-- @function setWinCount
-- @tparam int32 teamSide Team side (`1` or `2`).
-- @tparam int32 wins Win count.
function setWinCount(teamSide, wins) end

--- Block the current script for a given number of seconds.
-- @function sleep
-- @tparam float64 seconds Time to sleep, in seconds.
function sleep(seconds) end

--- Load a SND file.
-- @function sndNew
-- @tparam string filename SND file path.
-- @treturn Snd snd SND userdata.
function sndNew(filename) end

--- Play a sound from a SND object.
-- @function sndPlay
-- @tparam Snd snd SND userdata.
-- @tparam int32 group Sound group number.
-- @tparam int32 number Sound number within the group.
-- @tparam[opt=100] int32 volumescale Volume scale (percent).
-- @tparam[opt=0.0] float32 pan Stereo panning (engine-specific range).
-- @tparam[opt=0] int loopstart Loop start position.
-- @tparam[opt=0] int loopend Loop end position.
-- @tparam[opt=0] int startposition Start position.
function sndPlay(snd, group, number, volumescale, pan, loopstart, loopend, startposition) end

--- Check if a given sound is currently playing.
-- @function sndPlaying
-- @tparam Snd snd SND userdata.
-- @tparam int32 group Sound group number.
-- @tparam int32 number Sound number within the group.
-- @treturn boolean playing `true` if the sound is playing.
function sndPlaying(snd, group, number) end

--- Stop a sound from a SND object.
-- @function sndStop
-- @tparam Snd snd SND userdata.
-- @tparam int32 group Sound group number.
-- @tparam int32 number Sound number within the group.
function sndStop(snd, group, number) end

--- Return a random float in the engine's random range.
-- @function sszRandom
-- @treturn float64 value Random value (engine-specific range, typically 0.0–1.0).
function sszRandom() end

--- Enable single-frame stepping mode.
-- @function frameStep
function frameStep() end

--- Stop all character sounds.
-- @function stopAllSound
function stopAllSound() end

--- Stop background music playback.
-- @function stopBgm
function stopBgm() end

--- [redirectable] Stop all sounds for the debug watch character.
-- @function stopSnd
function stopSnd() end

--- Synchronize with external systems (e.g. netplay).
-- @function synchronize
-- @raise Raises an error if synchronization fails.
function synchronize() end

--- Offset a text sprite's position by the given amounts.
-- @function textImgAddPos
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 dx X offset to add.
-- @tparam float32 dy Y offset to add.
function textImgAddPos(ts, dx, dy) end

--- Append text to an existing text sprite.
-- @function textImgAddText
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam string text Text to append (no automatic newline).
function textImgAddText(ts, text) end

--- Copy velocity settings from another text sprite.
-- @function textImgApplyVel
-- @tparam TextSprite ts Text sprite userdata to modify.
-- @tparam TextSprite source Source text sprite whose velocity is copied.
function textImgApplyVel(ts, source) end

--- Print debug information about a text sprite.
-- @function textImgDebug
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam[opt] string prefix Optional text printed before the debug info.
function textImgDebug(ts, prefix) end

--- Queue drawing of a text sprite.
-- @function textImgDraw
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam[opt] int16 layer Layer to draw on (defaults to `ts.layerno`).
function textImgDraw(ts, layer) end

--- Measure the width of a text string for a font.
-- @function textImgGetTextWidth
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam string text Text to measure.
-- @treturn int32 width Width of the rendered text in pixels.
function textImgGetTextWidth(ts, text) end

--- Create a new empty text sprite.
-- @function textImgNew
-- @treturn TextSprite ts Newly created text sprite userdata.
function textImgNew() end

--- Reset a text sprite to its initial values.
-- @function textImgReset
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam[opt] table parts If omitted or `nil`, resets everything.
--   If provided, must be an array-like table of strings, each one of:
--   - `"pos"` – reset position to initial  
--   - `"scale"` – reset scale to initial  
--   - `"window"` – reset window to initial  
--   - `"velocity"` – reset velocity to initial  
--   - `"text"` – reset text to initial  
--   - `"palfx"` – clear PalFX  
--   - `"delay"` – reset text delay timer
function textImgReset(ts, parts) end

--- Set per-frame acceleration for a text sprite.
-- @function textImgSetAccel
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 ax X acceleration.
-- @tparam float32 ay Y acceleration.
function textImgSetAccel(ts, ax, ay) end

--- Set text alignment for a text sprite.
-- @function textImgSetAlign
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam int32 align Alignment value (engine-specific constants, e.g. left/center/right).
function textImgSetAlign(ts, align) end

--- Set the font bank index for a text sprite.
-- @function textImgSetBank
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam int32 bank Font bank index.
function textImgSetBank(ts, bank) end

--- Set the RGBA color for a text sprite.
-- @function textImgSetColor
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam int32 r Red component (0–255).
-- @tparam int32 g Green component (0–255).
-- @tparam int32 b Blue component (0–255).
-- @tparam[opt=255] int32 a Alpha component (0–255).
function textImgSetColor(ts, r, g, b, a) end

--- Assign a font object to a text sprite.
-- @function textImgSetFont
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam Fnt fnt Font userdata to use.
function textImgSetFont(ts, fnt) end

--- Set the position of a text sprite.
-- @function textImgSetPos
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam[opt] float32 x X position; if omitted, uses the initial X offset.
-- @tparam[opt] float32 y Y position; if omitted, uses the initial Y offset.
function textImgSetPos(ts, x, y) end

--- Set friction applied to a text sprite's velocity each update.
-- @function textImgSetFriction
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 fx X friction factor.
-- @tparam float32 fy Y friction factor.
function textImgSetFriction(ts, fx, fy) end

--- Set the drawing layer for a text sprite.
-- @function textImgSetLayerno
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam int16 layer Layer number.
function textImgSetLayerno(ts, layer) end

--- Set the local coordinate space for a text sprite.
-- @function textImgSetLocalcoord
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 width Local coordinate width.
-- @tparam float32 height Local coordinate height.
function textImgSetLocalcoord(ts, width, height) end

--- Set the maximum visible distance for a text sprite.
-- @function textImgSetMaxDist
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 xDist Maximum X distance.
-- @tparam float32 yDist Maximum Y distance.
function textImgSetMaxDist(ts, xDist, yDist) end

--- Set the scale of a text sprite.
-- @function textImgSetScale
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 sx X scale.
-- @tparam float32 sy Y scale.
function textImgSetScale(ts, sx, sy) end

--- Set the text content of a text sprite.
-- @function textImgSetText
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam string text Text to display.
function textImgSetText(ts, text) end

--- Set per-character text delay for a text sprite.
-- @function textImgSetTextDelay
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 delay Delay between characters (frames, engine-specific).
function textImgSetTextDelay(ts, delay) end

--- Set character spacing for a text sprite.
-- @function textImgSetTextSpacing
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 spacing Character spacing amount.
function textImgSetTextSpacing(ts, spacing) end

--- Enable or disable word wrapping for a text sprite.
-- @function textImgSetTextWrap
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam boolean wrap If `true`, enables text wrapping.
function textImgSetTextWrap(ts, wrap) end

--- Set velocity for a text sprite.
-- @function textImgSetVelocity
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 vx X velocity.
-- @tparam float32 vy Y velocity.
function textImgSetVelocity(ts, vx, vy) end

--- Set the clipping window for a text sprite.
-- @function textImgSetWindow
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 x1 Left coordinate.
-- @tparam float32 y1 Top coordinate.
-- @tparam float32 x2 Right coordinate.
-- @tparam float32 y2 Bottom coordinate.
function textImgSetWindow(ts, x1, y1, x2, y2) end

--- Set X shear (italic-style slant) for a text sprite.
-- @function textImgSetXShear
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 xshear Shear value along X.
function textImgSetXShear(ts, xshear) end

--- Set rotation angle for a text sprite.
-- @function textImgSetAngle
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 angle Rotation angle in degrees.
function textImgSetAngle(ts, angle) end

--- Set rotation angle around the X axis for a text sprite.
-- @function textImgSetXAngle
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 xangle X-axis rotation angle.
function textImgSetXAngle(ts, xangle) end

--- Set rotation angle around the Y axis for an animation.
-- @function animSetYAngle
-- @tparam Anim anim Animation userdata.
-- @tparam float32 yangle Y-axis rotation angle.
function animSetYAngle(anim, yangle) end

--- Set projection mode for an animation.
-- @function animSetProjection
-- @tparam Anim anim Animation userdata.
-- @tparam int32|string projection Projection mode. Can be a numeric engine constant, or one of:
--   - `"orthographic"`
--   - `"perspective"`
--   - `"perspective2"`
function animSetProjection(anim, projection) end

--- Set focal length used for perspective projection on an animation.
-- @function animSetFocalLength
-- @tparam Anim anim Animation userdata.
-- @tparam float32 fLength Focal length value.
function animSetFocalLength(anim, fLength) end

--- Set rotation angle around the Y axis for a text sprite.
-- @function textImgSetYAngle
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 yangle Y-axis rotation angle.
function textImgSetYAngle(ts, yangle) end

--- Set projection mode for a text sprite.
-- @function textImgSetProjection
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam int32|string projection Projection mode. Can be a numeric engine constant, or one of:
--   - `"orthographic"`
--   - `"perspective"`
--   - `"perspective2"`
function textImgSetProjection(ts, projection) end

--- Set focal length used for perspective projection on a text sprite.
-- @function textImgSetFocalLength
-- @tparam TextSprite ts Text sprite userdata.
-- @tparam float32 fLength Focal length value.
function textImgSetFocalLength(ts, fLength) end

--- Update a text sprite's internal state (position, delays, etc.).
-- @function textImgUpdate
-- @tparam TextSprite ts Text sprite userdata.
function textImgUpdate(ts) end

--- Toggle display of collision boxes.
-- @function toggleClsnDisplay
-- @tparam[opt] boolean state If provided, sets collision box display on/off; otherwise toggles it.
function toggleClsnDisplay(state) end

--- Toggle or cycle debug display.
-- @function toggleDebugDisplay
-- @tparam[opt] boolean dummy If provided (any value), simply toggles the debug display.
--   If omitted, cycles the debug display through characters and eventually disables it.
function toggleDebugDisplay(dummy) end

--- Toggle fullscreen mode.
-- @function toggleFullscreen
-- @tparam[opt] boolean state If provided, sets fullscreen on/off; otherwise toggles it.
function toggleFullscreen(state) end

--- Toggle lifebar visibility.
-- @function toggleLifebarDisplay
-- @tparam[opt] boolean hide If provided, hides (`true`) or shows (`false`) the lifebar; otherwise toggles.
function toggleLifebarDisplay(hide) end

--- Toggle "max power" cheat mode.
-- @function toggleMaxPowerMode
-- @tparam[opt] boolean state If provided, sets max power mode on/off; otherwise toggles it.
--   When enabled, all root players' power is set to their maximum.
function toggleMaxPowerMode(state) end

--- Toggle global sound output.
-- @function toggleNoSound
-- @tparam[opt] boolean state If provided, sets mute on/off; otherwise toggles it.
function toggleNoSound(state) end

--- Toggle game pause.
-- @function togglePause
-- @tparam[opt] boolean state If provided, sets pause on/off; otherwise toggles it.
function togglePause(state) end

--- Enable or disable all instances of a given player.
-- @function togglePlayer
-- @tparam int32 playerNo Player number (1-based).
function togglePlayer(playerNo) end

--- Toggle vertical sync (VSync).
-- @function toggleVSync
-- @tparam[opt] int32 mode If provided, sets VSync mode (0 = off, 1 = on); otherwise toggles between 0 and 1.
function toggleVSync(mode) end

--- Toggle wireframe rendering mode (debug only).
-- @function toggleWireframeDisplay
-- @tparam[opt] boolean state If provided, sets wireframe display on/off; otherwise toggles it.
function toggleWireframeDisplay(state) end

--- Update background music volume to match current settings.
-- @function updateVolume
function updateVolume() end

--- Get the engine version string.
-- @function version
-- @treturn string ver Engine version and build time.
function version() end

--- Play a sound from a Sound object on the shared sound channel pool.
-- @function wavePlay
-- @tparam Sound s Sound userdata.
-- @tparam[opt] int32 group Optional group number.
-- @tparam[opt] int32 number Optional sound number within the group.
function wavePlay(s, group, number) end

Full list of functions externalized by engine into Lua is not documented at this point (you will have to dive into existing scripts to learn their names and how to use them for now). Instead the below list is limited only to Lua functions that works pretty much the same way as CNS/ZSS triggers (useful for implementing more advanced Arcade Paths / Story Mode arcs). Functions without additional comment either work like CNS/ZSS trigger equivalents or are self explanatory. Triggers that in CNS return so called boolean int here returns true or false instead of 1 or 0. All functions are case sensitive. They work from within Lua both in-match and after match.

Trigger Redirection

Redirection returns true if it successfully finds n-th player, or false otherwise. Lua "trigger" functions code used after redirection will be executed via matched player/helper, as long as new redirection is not used.

  • player(n)
  • parent()
  • root()
  • helper(n)
  • target(n)
  • partner(n)
  • enemy(n)
  • enemynear(n)
  • playerid(n)
  • playerindex(n)
  • p2()
  • stateowner()
  • helperindex(n)

Trigger with CNS equivalents

  • ailevel
  • airjumpcount
  • alive
  • alpha
  • angle
  • anim
  • animelemno
  • animelemtime
  • animelemvar
  • animexist
  • animlength
  • animplayerno
  • animtime
  • attack
  • attackmul
  • authorname
  • backedge
  • backedgebodydist
  • backedgedist
  • bgmvar
  • botboundbodydist
  • botbounddist
  • bottomedge
  • cameraposX
  • cameraposY
  • camerazoom
  • canrecover
  • clamp
  • clsnoverlap
  • clsnvar
  • combocount
  • command
  • consecutivewins
  • const
  • const1080p
  • const240p
  • const480p
  • const720p
  • ctrl
  • debugmode
  • decisiveround
  • defence
  • defencemul
  • displayname
  • dizzy
  • dizzypoints
  • dizzypointsmax
  • drawgame
  • drawpal
  • envshakevar
  • explodvar
  • facing
  • fightscreenstate
  • fightscreenvar
  • fighttime
  • firstattack
  • frontedge
  • frontedgebodydist
  • frontedgedist
  • fvar
  • gameheight
  • gamemode
  • gameOption
  • gametime
  • gamevar
  • gamewidth
  • gethitvar
  • groundlevel
  • guardbreak
  • guardcount
  • guardpoints
  • guardpointsmax
  • helperindexexist
  • helpervar
  • hitbyattr
  • hitcount
  • hitdefattr
  • hitdefvar
  • hitfall
  • hitover
  • hitoverridden
  • hitpausetime
  • hitshakeover
  • hitvelX
  • hitvelY
  • hitvelZ
  • id
  • ikemenversion
  • incustomanim
  • incustomstate
  • index
  • inguarddist
  • inputtime
  • introstate
  • isasserted
  • ishelper
  • ishometeam
  • ishost
  • jugglepoints
  • lastplayerid
  • layerNo
  • leftedge
  • lerp
  • life
  • lifemax
  • localcoordX
  • localcoordY
  • lose
  • loseko
  • losetime
  • map
  • matchno
  • matchover
  • memberno
  • motifstate
  • motifvar
  • movecontact
  • movecountered
  • moveguarded
  • movehit
  • movehitvar
  • movereversed
  • movetype
  • mugenversion
  • name
  • numenemy
  • numexplod
  • numhelper
  • numpartner
  • numplayer
  • numproj
  • numprojid
  • numstagebg
  • numtarget
  • numtext
  • offsetX
  • offsetY
  • outrostate
  • p2bodydistX
  • p2bodydistY
  • p2bodydistZ
  • p2distX
  • p2distY
  • p2distZ
  • p2life
  • p2movetype
  • p2stateno
  • p2statetype
  • palfxvar
  • palno
  • parentdistX
  • parentdistY
  • parentdistZ
  • pausetime
  • physics
  • playeridexist
  • playerindexexist
  • playerno
  • playernoexist
  • posX
  • posY
  • posZ
  • power
  • powermax
  • prevanim
  • prevmovetype
  • prevstateno
  • prevstatetype
  • projcanceltime
  • projclsnoverlap
  • projcontacttime
  • projguardedtime
  • projhittime
  • projvar
  • ratiolevel
  • receiveddamage
  • receivedhits
  • redlife
  • reversaldefattr
  • rightedge
  • rootdistX
  • rootdistY
  • rootdistZ
  • roundno
  • roundsexisted
  • roundstate
  • roundswon
  • roundtime
  • runorder
  • scaleX
  • scaleY
  • scaleZ
  • score
  • scoretotal
  • screenheight
  • screenposX
  • screenposY
  • screenwidth
  • selfanimexist
  • selfstatenoexist
  • sign
  • soundvar
  • sprpriority
  • stagebackedgedist
  • stagebgvar
  • stageconst
  • stagefrontedgedist
  • stagetime
  • stagevar
  • standby
  • stateno
  • statetype
  • sysfvar
  • sysvar
  • teamleader
  • teammode
  • teamside
  • teamsize
  • tickspersecond
  • time
  • timeelapsed
  • timemod
  • timeremaining
  • timetotal
  • topboundbodydist
  • topbounddist
  • topedge
  • uniqhitcount
  • var
  • velX
  • velY
  • velZ
  • win
  • winhyper
  • winko
  • winperfect
  • winspecial
  • wintime
  • xangle
  • xshear
  • yangle
  • zoomvar

Lua/debug only triggers

  • animelemcount
  • animtimesum
  • continue
  • credits
  • gameend
  • gamefps
  • gameRunning
  • gamespeed
  • matchtime
  • network
  • paused
  • postmatch
  • roundover
  • roundstart
  • selectno
  • stateownerid
  • stateownername
  • stateownerplayerno
  • winnerteam

Regardless of what kind of Lua code you're working on it's useful to have a way to dynamically print the result of it on screen. In order to do so start Ikemen Go with any command-line interpreter (Command Prompt on Windows, Terminal on unix, etc.). On Windows the easiest way to do it is creating a batch file.

Use Lua print() function to print out values or calculations on those values to command-line window. Basic information how to use it can be found in this tutorial.

⚠️ **GitHub.com Fallback** ⚠️