Solarus Wiki

A wiki for the Solarus engine community

User Tools

Site Tools


learning_lua

Learning Lua

Lua is a scripting language very popular in the gaming area. Lots of commercial games, including World of Warcraft, use Lua to define their content.

We chose Lua for Solarus because it is easy to learn. A minimal effort is required to be able to program your first map. Most scripting languages are also easy to learn, but Lua is minimal, and yet very powerful because of its flexibility.

The Solarus engine is programmed in C++, and a quest that uses Solarus is programmed in Lua. The C++ part (the engine) does all the heavy computations (for example, collision checks) and the low-level operations like drawing the screen, animating sprites and playing sounds. As a quest maker, you are not much interested in implementing these algorithms. On the contrary, you want to define the game logic. Your Lua scripts describe the behavior of enemies, what happens when pressing a switch on a specific map. They will also implement the title screen and the head-up display.

Both parts (the C++ engine and Lua scripts of your quest) communicate through the Solarus Lua API. The communication works in both ways: you can call functions of the engine (example : you want to move a non-playing character) and the engine calls your own functions (example: be informed that an enemy was just killed). But before using this Solarus API, you have to learn the basics of Lua.

To learn Lua, we recommend to read the Programming in Lua book. Read at least Chapters 1 to 5, and then you will know enough to make your first scripts and to understand the Solarus Lua API reference. Later, you should also read chapters 11, 13, 16, 18, 19, 20 to really master the language.

learning_lua.txt · Last modified: 2013/09/17 10:22 by christopho