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.

campaign_message_box(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.

TODO(wl-zocker): This function should be used by all tutorials, campaigns and scenario maps

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.

message_box_objective(player, message)

DEPRECATED, use campaign_message_with_objective instead. Calls message_box(player, message.title, message.body, message). Also adds an objective defined in obj_name, obj_title and obj_body. This method should gather all options that are used often to avoid reimplementation in every single scenario script.

Parameters
  • player – the recipient of the message

  • message – a table that contains all information

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 calls message_box(), which waits until the player leaves the roadbuilding mode. Use this with care because it can be very interruptive. Default: false.

Returns

the objective if defined, nil otherwise