Lua API

Input module

Functions for prompting the player for input.

Usage

local Input = ELONA.require("core.Input")

Functions

yes_no (message) Prompts the player to select "yes" or "no".
prompt_number (message, max[, initial]) Prompts the player to choose a number.
prompt_text (message, is_cancelable) Prompts the player to enter text.
prompt_choice (choices) Prompts the player to select from a list of choices.
prompt_dialog (message, portrait_id, speaker_name[, default_index], choices[, impression][, interest]) Creates a dialog window like the one normally shown when talking to a character.
prompt_dialog (message, chara_image, speaker_name[, default_index], choices[, impression][, interest]) Creates a dialog window like the one normally shown when talking to a character.
start_dialog (speaker[, dialog]) Starts a dialog with a character.
choose_ally (operation) Prompts the player to choose an ally.
enqueue_macro (action, actions) Enqueues an action or a list of actions into the macro action queue.
clear_macro_queue () Clears any actions that haven't been run yet in the macro action queue.
ignore_keywait () Disables input/macro keywait for this frame.
any_key_pressed () Returns true if any key is pressed.

Functions

# yes_no (message)

Prompts the player to select "yes" or "no".

Parameters:
  • message : (string) a message to display
Returns:
  • (bool) true if "yes" was selected.
Or
  • (nil) if canceled.
Usage:
local result = Input.yes_no("Yes or no?")

 if result == nil then
 GUI.txt("You canceled. ")
 elseif result then
 GUI.txt("You chose yes. ")
 else
 GUI.txt("You chose no. ")
 end
# prompt_number (message, max[, initial])

Prompts the player to choose a number.

Raises an error if max is less than 0.

Parameters:
  • message : (string) a message to display
  • max : (num) the maximum number choosable
  • initial : (num) the initial value (optional)
Returns:
  • (num) the number chosen
Or
  • (nil) if canceled, or max < 0
Usage:
local result = Input.prompt_number("Which character to spawn? ", 353)
 if result then
 local chara = Chara.create(25, 25, result)
 if chara then
 GUI.txt("Spawned " .. chara.name .. ". ")
 end
 else
 GUI.txt("Never mind.")
 end
# prompt_text (message, is_cancelable)

Prompts the player to enter text.

Parameters:
  • message : (string) a message to display
  • is_cancelable : (bool) whether or not the dialog can be canceled
Returns:
  • (string) the text that was input
  • (nil) if canceled
Usage:
local result = Input.prompt_text("What text?", true)

 if result then
 GUI.txt("You typed \"" .. result .. "\". ")
 else
 GUI.txt("Never mind. ")
 end
# prompt_choice (choices)

Prompts the player to select from a list of choices.

Raises an error if no arguments are provided.

Parameters:
  • choices : (table) a list of string choices
Returns:
  • (num) the index of the item chosen, starting from 1
Or
  • (nil) if canceled
Usage:
GUI.txt("Which? ")
 local choices = {"First", "Second", "Third"}
 local result = Input.prompt_choice(choices)

 if result then
 GUI.txt("You chose \"" .. choices[result] .. "\". ")
 else
 GUI.txt("Never mind. ")
 end
# prompt_dialog (message, portrait_id, speaker_name[, default_index], choices[, impression][, interest])

Creates a dialog window like the one normally shown when talking to a character.

Parameters:
  • message : (string) Message to display.
  • portrait_id : (string) Portrait ID of the speaker.
  • speaker_name : (string) Name of the speaker to display.
  • default_index : (num) Default choice to use if canceled. (optional)
  • choices : ({string,...}) An array of string choices for the dialog.
  • impression : (num) Impression to display. (optional)
  • interest : (num) Interest to display. (optional)
Returns:
  • num index of the selected item, or the default if canceled
# prompt_dialog (message, chara_image, speaker_name[, default_index], choices[, impression][, interest])

Creates a dialog window like the one normally shown when talking to a character.

Parameters:
  • message : (string) Message to display.
  • chara_image : (num) Character chip of the speaker.
  • speaker_name : (string) Name of the speaker to display.
  • default_index : (num) Default choice to use if canceled. (optional)
  • choices : ({string,...}) An array of string choices for the dialog.
  • impression : (num) Impression to display. (optional)
  • interest : (num) Interest to display. (optional)
Returns:
  • num index of the selected item, or the default if canceled
# start_dialog (speaker[, dialog])

Starts a dialog with a character.

Parameters:
  • speaker : (LuaCharacter) Character who will speak.
  • dialog : (string) Dialog ID to use. Defaults to the one in the character's definition. (optional)
# choose_ally (operation)

Prompts the player to choose an ally.

Parameters:
  • operation : (ChooseAllyOperation) the operation to apply
Returns:
Or
# enqueue_macro (action, actions)

Enqueues an action or a list of actions into the macro action queue.

It will be run in order of insertion the next time input is queried.

Parameters:
  • action : (string) the action to run.
  • actions : (table) an array of actions to run.
Usage:
Macro.enqueue("north")
  Macro.enqueue({"east", "wait", "northwest"})
# clear_macro_queue ()

Clears any actions that haven't been run yet in the macro action queue.

# ignore_keywait ()

Disables input/macro keywait for this frame.

# any_key_pressed ()

Returns true if any key is pressed.

Returns:
  • (bool)