Bitfighter
021
The Bitfighter Lua Documentation - Robots, Levelgens, and Plugins
|
Levelgens are a little different. While the entire purupose of a bot is to actively participate in a game, many levelgens will not stick around after the level has been loaded. For a basic levelgen, the entire script might be contained in the main() function – it might create some items, and do nothing more.
If a level has a levelgen script, its main function is executed as the level is loaded, after all objects defined in the level file have been created. Therefore a levelgen can act upon those objects, either altering them, deleting them, or by adding completely new objects.
Levelgens can also subscribe to events; their event handlers will be called throughout the game as events are fired.
Unlike robots, levelgens are not automatically subscribed to the Tick event.
You can build on this script by expanding the main() function, or by subscribing to events and adding event listeners to respond to them. See Subscribing to Events for more information.
You can do some pretty neat things with even a basic levelgen script, such as add objects to levels.
Modify your hello_world script to look like this:
Now when you start your level, you should see a ring of resource items!
If you don't see them, the script might be crashing. Errors are logged to the console, so be sure to check there when something isn't working. To run your script again, quit the game and restart it.