Difference between revisions of "Introduction to Mission Scripting"

From PioneerWiki
Jump to: navigation, search
(initial import of mission scripting intro)
(No difference)

Revision as of 22:33, 10 September 2012

Pioneer is extensible through the Lua scripting language. This document is intended to take the reader through the basics of coding up a mission for Pioneer, with a worked example. The assumption is made that the reader is already aware of basic programming concepts, and in particular has some knowledge of the Lua programming language.

If you are not familiar with Lua, the lua-users wiki: Learning Lua page is a good place to start.

Pioneer's Lua environment

Pioneer contains a full Lua interpreter. There are three instances of the interpreter; one for defining models, one for defining the galaxy, and one for writing mission scripts. This document is focused exclusively on the latter of the three.

When Pioneer is started, the universe is generated. After the universe is generated, Pioneer traverses the data/libs directory and all subdirectories, looking for files ending in the .lua extension. Each of these files are loaded into the interpreter and run. After these are run, Pioneer traverses the data/modules directory and does exactly the same thing. After this, the main menu is shown, and the player can begin a game.

The order in which the Lua scripts are loaded and run is not strictly defined, other than the fact that scripts in the data/libs directory will be executed before scripts in the data/modules directory.

Any globally defined functions or variables defined in those scripts will be available to any other scripts. We recommend that any functions or variables not explicitly intended for use by other scripts be declared with the local keyword, which will make them available only within the scope of the current file.

Chapters: