LuaWML/Display

From The Battle for Wesnoth Wiki
< LuaWML
Revision as of 08:35, 15 March 2010 by Silene (talk | contribs) (Split LuaWML page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This page describes the LuaWML functions and helpers for displaying messages to the user.

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.

_ = 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_text(unit.x, unit.y, "<span color='#ff0000'>Ouch</span>")

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" })