Difference between revisions of "LuaAPI/plugins"

From The Battle for Wesnoth Wiki
Line 2: Line 2:
 
A plugin is a Lua script loaded via the command-line option <tt>--plugin</tt> that runs as a coroutine in parallel with the game UI. Examples of their use in mainline are the <tt>host.lua</tt> and <tt>join.lua</tt> scripts which are used during CI to test hosting and joining a game through the multiplayer lobby.
 
A plugin is a Lua script loaded via the command-line option <tt>--plugin</tt> that runs as a coroutine in parallel with the game UI. Examples of their use in mainline are the <tt>host.lua</tt> and <tt>join.lua</tt> scripts which are used during CI to test hosting and joining a game through the multiplayer lobby.
  
Within the script, data from the game is retrieved via <tt>coroutine.yield()</tt> which returns three values: events, context, and info.
+
Within the script, data from the game is retrieved via <tt>coroutine.yield()</tt> which returns three values: events, context, and info:
 +
events, context, info = coroutine.yield()
 +
 
 
=== Events ===
 
=== Events ===
 
A table of events the plugin manager has been made aware of, with each event containing the event name in the [1] index and the event data in the [2] index.
 
A table of events the plugin manager has been made aware of, with each event containing the event name in the [1] index and the event data in the [2] index.

Revision as of 01:22, 28 September 2022

General

A plugin is a Lua script loaded via the command-line option --plugin that runs as a coroutine in parallel with the game UI. Examples of their use in mainline are the host.lua and join.lua scripts which are used during CI to test hosting and joining a game through the multiplayer lobby.

Within the script, data from the game is retrieved via coroutine.yield() which returns three values: events, context, and info:

events, context, info = coroutine.yield()

Events

A table of events the plugin manager has been made aware of, with each event containing the event name in the [1] index and the event data in the [2] index.

Chat

Currently there is only the chat event, which occurs when a chat message or a whisper is sent and contains the following attributes:

  • sender - String. The player sending the message.
  • message - String. The message being sent.
  • whisper - Boolean. Whether the message was sent as a whisper or as a general chat message.

Context

This object contains various functions which can be called to change or set data (mutators).

Info

This object contains the name attribute which identifies which context the game is currently in, as well as various functions to retrieve data (accessors).