Solarus quests
1.6
Quest maker's reference
|
This is the API specification of Lua functions, methods, callbacks and types defined by Solarus. This documentation page is intented to quest makers who want to write scripts for their maps, items, enemies and menus. For the point of view of the C++ code of the engine, see the documentation of class LuaContext.
Most of the data types defined in the C++ engine (like sprites, map entities, movements, savegames, etc.) are exported as Lua types in the scripting API of Solarus. We give here the full reference of these types and the functions available for each type. The API exports C++ functions and C++ datatypes that may be used by your scripts. Examples of such features are creating a sprite, drawing an image or moving an enemy. In the opposite way, Solarus will also call your own Lua functions (if you define them), for example to notify your script that an enemy has reached an obstacle, that a pressure plate has just been activated or that the hero is talking to a particular non-playing character.
The following script files are loaded by the engine when they exist:
main.lua
): global script that controls the menus (if any) before starting a game and decides to start a game.maps/XXXX.lua
): controls the map XXXX
. Called when the player enters the map.enemies/XXXX.lua
): controls an enemy whose breed is XXXX
. Called when an enemy of this breed is created on the map.items/XXXX.lua
): controls the equipment item named XXXX
. Called when a savegame is loaded or created.All these various scripts run in the same Lua state. In other words, they share global values.
Interactions between your Lua world and the engine are managed through a predefined global table called sol
. The whole Solarus Lua API is available in the sol
table. It contains functions, types and values that allow you to interact with the C++ engine.
Most types of the Lua API (like game, item, map, entity, movement and sprite) are Lua userdata that have something special: they can also be indexed like tables. This mechanism is used by the engine when it needs to invoke callback methods that you defined on your objects. But you can also extend these objects with your own functions and data. This is very useful in the game and map objects to implement and store everything that is not built-in in the Solarus API: your pause menu, your HUD, a puzzle, or some properties and utility functions specific to your quest.
The following features are defined in the global sol
table. See the specification page of each feature for more details.