LuaAPI/old

From The Battle for Wesnoth Wiki



Functionalities of the game engine are available through the functions contained in the wesnoth global table. Some of these functions return proxy tables. Writes to fields marked "read-only" are ignored. The __cfg fields return plain tables; in particular, writes do not modify the original object, and reads return the values from the time the dump was performed.

Some helper functions are provided by the lua/helper.lua library. They are stored inside a table that is returned when loading the library with wesnoth.require.

helper = wesnoth.require "lua/helper.lua"

WML variables

Events and WML actions

User interface

Map and terrains

Time of day schedule

Units

Sides

Pathfinder

Lua files

Location sets

Miscellaneous

Functions that should not be used

If you take a look at Wesnoth's own lua files, you might find some undocumented functions use in the implementations of WML tags. Where possible, you should avoid using them, as they might be changed or removed with no compatibility for further releases. Instead, use the corresponding wml tags (in lua you can use wesnoth.wml_actions.tag_name(cfg), though keep in mind that this won't substitute variables in the config).

If uncertain whether an undocumented feature is safe to use, ask on the forums, Discord, or IRC. It may turn out that someone simply forgot to add it to the wiki.

  • wesnoth.redraw
  • wesnoth.set_menu_item
  • wesnoth.clear_menu_item
  • wesnoth.modify_ai
  • wesnoth.print
  • wesnoth.end_level
This page was last edited on 1 July 2023, at 18:12.