LuaWML/Display
This page describes the LuaWML functions and helpers for interfacing with the user.
Contents
wesnoth.message
Displays a string in the chat window and dumps it to the lua/info log domain (--log-info=scripting/lua on the command-line).
wesnoth.message "Hello World!"
The chat line header is "<Lua>" by default, but it can be changed by passing a string before the message.
wesnoth.message("Big Brother", "I'm watching you.") -- will result in "<Big Brother> I'm watching you."
See also helper.wml_error for displaying error messages.
wesnoth.textdomain
Creates a function proxy for lazily translating strings from the given domain.
-- #textdomain "my-campaign" -- the comment above ensures the subsequent strings will be extracted to the proper domain _ = wesnoth.textdomain "my-campaign" wesnoth.set_variable("my_unit.description", _ "the unit formerly known as Hero")
The metatable of the function proxy appears as "message domain". The metatable of the translatable strings (results of the proxy) appears as "translatable string".
The translatable strings can be appended to other strings/numbers with the standard .. operator. Translation can be forced with the standard tostring operator in order to get a plain string.
wesnoth.message(string.format(tostring(_ "You gain %d gold."), amount))
wesnoth.float_label
Pops some text above a map tile.
wesnoth.float_label(unit.x, unit.y, "<span color='#ff0000'>Ouch</span>")
wesnoth.scroll_to_tile
Scrolls the map to the given location. If true is passed as the third parameter, scrolling is disabled if the tile is hidden under the fog.
local u = wesnoth.get_units({ id = "hero" })[1] wesnoth.scroll_to_tile(u.x, u.y)
wesnoth.set_music
Sets the given table as an entry into the music list. See MusicListWML for the recognized attributes.
wesnoth.set_music { name = "traveling_minstrels.ogg" }
Passing no argument forces the engine to take into account all the recent changes to the music list. (Note: this is done automatically when sequences of WML commands end, so it is useful only for long events.)
helper.get_user_choice
Displays a WML message box querying a choice from the user. Attributes and options are taken from given tables (see [message]). The index of the selected option is returned.
local result = helper.get_user_choice({ speaker = "narrator" }, { "Choice 1", "Choice 2" })