Lua Bots documentation and samples?

Discussion of Lua and LuaWML support, development, and ideas.

Moderators: Forum Moderators, Developers

Post Reply
C4nt3r
Posts: 9
Joined: November 3rd, 2018, 2:49 pm

Lua Bots documentation and samples?

Post by C4nt3r » September 9th, 2019, 9:33 pm

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?


User avatar
Celtic_Minstrel
Developer
Posts: 1569
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Lua Bots documentation and samples?

Post by Celtic_Minstrel » September 23rd, 2019, 12:37 pm

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 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?
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.

User avatar
josteph
Developer
Posts: 740
Joined: August 19th, 2017, 6:58 pm

Re: Lua Bots documentation and samples?

Post by josteph » September 23rd, 2019, 1:35 pm

Useful info! Anyone have a minute to add it to the wiki?

Post Reply