Lua Bots documentation and samples?
Moderator: Forum Moderators
Lua Bots documentation and samples?
Maybe I’m blind, but I see WML and LUa reference, but can’t find documentation/tutorial where to start developing a bot and/or samples
Some idea?
Some idea?
- Celtic_Minstrel
- Developer
- Posts: 2222
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Lua Bots documentation and samples?
A Lua plugin is a script that returns a function to be run as a coroutine. It's called with no arguments, but every time it yields, the game engine passes it information about the current situation – for example, whether the game is showing the titlescreen, the multiplayer lobby, or a game. Depending on this, the
The only way to see what info and commands are available in a given context is to either examine the C++ source code (you can search for
To use your plugin, you launch Wesnoth with the
Some standard Wesnoth API functions are available to plugins, but most aren't, since they would depend on the presence of an actual game. For example, functions that manipulate WML, variables, and WFL are still available, but functions that deal with units or the maps will not work.
EDIT: Not sure why I said variables; those are obviously dependent on a game state. Maybe I was thinking of something else but typed out the wrong word?
context
variable offers different commands that can be run, and I believe the info
variable contains information about the current state – for example, when at the titlescreen you may be able to access the game's command-line parameters as info.command_line
.The only way to see what info and commands are available in a given context is to either examine the C++ source code (you can search for
plugins_context
to find the relevant locations) or write a script which prints the contents of the context
and info
variables. When at the titlescreen, the only options are play_multiplayer
and exit
, unfortunately – there's no way to enter a campaign or the map editor. But then, if you're making a bot, that'd be what you want anyway.To use your plugin, you launch Wesnoth with the
--plugin-<path/to/plugin.lua>
command-line argument. Once you have your bot working, you can add the --nogui
command-line parameter to run it without a user interface.Some standard Wesnoth API functions are available to plugins, but most aren't, since they would depend on the presence of an actual game. For example, functions that manipulate WML, variables, and WFL are still available, but functions that deal with units or the maps will not work.
EDIT: Not sure why I said variables; those are obviously dependent on a game state. Maybe I was thinking of something else but typed out the wrong word?
Re: Lua Bots documentation and samples?
Useful info! Anyone have a minute to add it to the wiki?