User:Bayo/script

UFO:AI scripts, inside .ufo files, are used to define most of the content of the game.

Yet, there is no global parser for this kind of files. Each node type use is own code to read one by one token and use them like it want. Then here some construction rules, scripts should respect to unify our scripts. It was not created from scratch, but from script legacy, with patch here and there to allow unifying and avoid most of ambiguous constructions.

This grammar is already used by our Eclipse plugin, to parse and validate scripts.

This grammar is simplified to stay readable. But some construction may not be allowed.

Values

NUMBER

A number, like 6, or 56.2

QUOTED_STRING

Any kind of content between to double quotes. It support common C escaping, like \n, \". Many composite types are also quoted, for example "2.5 4.0 2.5" which is a 3D vector; or "1 0 0 0.5" which can be a red color with some transparency.

NAMED_CONST

A named constant provided by the game. It must be in full upper case, for example EMPL_PILOT, and usualy there is only a set of available values. It should be always used when a value is hardcoded into the game (instead of a quoted string).

IDENTIFIER

An unique identifier of the script object.

REFERENCE

A reference to an unique identifier provided somewhere else in the script.

Structure

Block

A block contains sub nodes, which can contains another blocks. Usualy it is used like a set of properties (key-value structure). But it can be used like a sequence of definitions.

Others use it like a tuple to define a composite object. In this kind of way it can be better to use a block. At least you should think about the two ways. A block is more verbose but it is self descriptive and more easy to custom.