messages.lua¶

Functions to send messages to the player and to add objectives to campaigns.

send_message(player, title, body, parameters)

Sends a message to the player. If the popup parameter is true and the player is in building mode, the function waits until the player leaves the building mode before sending the message (only in singleplayer)

Parameters
• player – the recipient of the message

• title (string) – the localized title of the message

• body (string) – the localized body of the message. You can use rt functions here.

• parameters – Array of message parameters as defined in the Lua interface, for wl.game.Player, e.g. { field = f, popup = true }. The popup parameter must be set.

send_to_all(text[, heading])

Sends a game status message to all players.

Parameters
• text (string) – the localized body of the message. You can use rt functions here.

• heading (string) – the localized title of the message (optional)

message_box(player, title, message, parameters)

Waits if player is in building mode, then shows a scenario message box

Parameters
• player – the recipient of the message

• title (string) – the localized title of the message

• body (string) – the localized body of the message. You can use rt functions here.

• parameters – Array of message parameters as defined in the Lua interface, for wl.game.Player, e.g. { field = f }.

campaign_message_box(message[, sleeptime])

Sets message.h and message.w if not set and calls message_box(player, title, body, parameters) for player 1

Parameters
• message – the message to be sent

• sleeptime – ms spent sleeping after the message has been dismissed by the player

Besides the normal message arguments (see wl.Game.Player:message_box) the following ones can be used:

Parameters
• position – A string that indicates at which border of the screen the message box shall appear. Can be “top”, “bottom”, “right”, “left” or a combination (e.g. “topright”). Overrides posx and posy. Default: Center. If only one direction is indicated, the other one stays central.

• scroll_back – If true, the view scrolls/jumps back to where it came from. If false, the new location stays on the screen when the message box is closed. Default: False.

• show_instantly – If true, the message box is shown immediately. If false, this function will wait until the player leaves the roadbuilding mode. Use this with care because it can be very interruptive. Default: false.

add_campaign_objective(objective)

Adds an objective to a campaign.

Parameters

objective – The objective to be added. If the variable obj_name exists, obj_name, obj_title and obj_body are used. Otherwise, it needs to have a name, title, and body.

Returns

The new objective.

new_objectives(...)

Append an objective text with a header to a dialog box in a nice fashion. For displaying objectives with an extra title when an advisor is talking

Provides nice formatting for objective texts. The following arguments will be parsed:

• number: the number of objectives described in the body

• body: the objective text, e.g. created with function objective_text(heading, body)

Returns

a rich text object that contains the formatted objective text & title.

campaign_message_with_objective(message, objective[, sleeptime])

Sets message.h and message.w if not set and calls message_box(player, title, body, parameters) for player 1.

Adds an objective to the scenario afterwards.

Parameters
• message – the message to be sent

• objective – The objective to be added. If the variable obj_name exists, obj_name, obj_title and obj_body are used. Otherwise, it needs to have a name, title, and body.

• sleeptime – ms spent sleeping after the message has been dismissed by the player

Returns

The new objective.

set_objective_done(objective[, sleeptime])

Sets an objectve as done and sleeps for a bit.

Parameters
• objective – The objective to be marked as done.

• sleeptime – The milliseconds to sleep. Defaults to 3000.