Backup of Lua (2) Back


Back to History list

*General [#lacce35c]
**What is This? [#mc8bd8ba]

This is a reference for writing lua scripts to work in A1. At the time of creation, it lists every trigger and function available to lua scripts. It is expected that lua functionality will grow in A1, and as it does, so will this document. Not everything here is completely documented, and any help fixing that would be appreciated.

This is not a reference for lua itself - see lua.org for that.

**Running a Script [#n408ab40]

There are two ways to get a script to run - level specific MML, and selecting a script at the gather network game dialog. To use level specific MML, put the script in a TEXT resource in the map file. Then put in TEXT resource 128 MML telling A1 where to find the script, which in its most basic form is this:

	<marathon_levels>

	<level index="0">
	<lua resource="1000"/>
	</level>

	</marathon_levels>

By convention we use TEXT resource 1000+x to hold the script for level x, so the first level in the map file (which has level index 0) gets its script in TEXT resource 1000.

This works fine for single player games. It will also work for multiplayer games, but only if every player has a copy of the map file and selects it in enviroment prefs.

To use a script via the network game dialog, put then script in a text file. Then, at the gather network game dialog, select "use script", then select your script file.

When playing network games, even if you are not gathering, it's important not to have a map file with level specific MML selected in your environment prefs, unless it's the map file for the map you are playing. A1 will run the script for that map file, your game will go out of sync, and you'll be unhappy.

**Units [#o3107d79]

The unit for distance we use is World Units (WU) These are the same values you'd see in Forge or with F10 location display, and 1/1024 of what A1 uses internally and what you'd see in Pfhorte.

Units for speed are . . . well let's say they're messy. :)

公式にあるのをコピペ、後で翻訳予定(by pfhore,EMRの翻訳の資料のため)