This is a copy of Andrew Apted's Post over at the EDGE forums
I'm trying an experiment here, and will develop the COAL documentation in this thread (in the first post), updating it whenever I feel like it or somebody asks a question. The rest of the thread can be used for comments and questions.
COAL DOCUMENTATION
How EDGE Loads It
In EDGE 1.34 there are two files with hard-coded names (doom_ddf/coal_api.ec and doom_ddf/coal_hud.ec) which get loaded. As you can see, coal scripts use the "EC" extension.
Coal scripts can also get loaded from wads, each wad given with -file can contain a lump called COALHUDS which will be loaded, and functions (such as draw_all) can be replaced.
Messages about loading and compiling errors get printed on the console and into the EDGE.LOG file. Like most compilers, the first error can cause lots of bogus error messages on later lines (COAL is pretty bad here, due to the removal of semicolons from the syntax).
Type System
Coal is statically typed, which means variables and function parameters can only use a single type. For example if the variable takes strings, you cannot assign a number to it. (This is a big difference from Lua where values have a fixed type and variables can take any kind of values).
The available types are:
float : used for numbers (floating point), e.g. 123 or -7.654
string : used for strings, which are specified with double quotes, e.g. "foobar"
vector : used for a 3D coordinate in the world. Vector constants are three numbers surrounded by a single quote, such as '0 -1 2'
It is planned to have an entity type which can be used to read and modify things in the map, but this has not been implemented yet.
Arrays are also planned.
Operators
! boolean not, e.g. !0 == 1
^ raise to the power, e.g. 2^3 == 8
& integer bit-and, e.g. 3 & 6 == 4
| integer bit-or, e.g. 3 | 6 == 7
* multiplication
/ division
% modulo
+ addition
- subtraction
== equals
!= not equals
< less than
> greater than
<= less than or equals
>= greater than or equals
&& boolean and
|| boolean or
Precedence table (highest to lowest) :
^ * / % & |
+ -
== != < > <= >=
&& ||
The * operator can be used on two vectors, and the result is the dot product (i.e. A * B calculates A.x * B.x + A.y * B.y + A.z * B.z).
The + operator can concatenate two strings, or a string and a float or vector (but the string must be on the left side). Hence a useful idiom is doing "" + x to convert a number to a string.
There is no unary - operator, to negate a value you need to do this: 0 - x
The && and || boolean operators are short-circuit, which means that the right side is not evaluated if the result is known from the left side only. For example: (1 && somefunc()) will never call that function.
Declaration Kinds
The following things can be declared globally: variables, constants, functions, and modules.
All of those (except for modules) can also be declared inside modules.
Within functions only variables can be declared (not constants, functions etc).
Global variables, constants and functions can be redeclared by later code (especially by a newer file), so long as the types are the same. Redefining a constant means that previous code using that constant will use the new value (in COAL constants are really just read-only variables).
Modules do not get redeclared, instead if the module already exists then the new contents are simply added to the existing module, and previous stuff can be redefined too.
Syntax for Variables and Constants
Variables are declared like this. When the type is not specified, float is assumed.
var name
var name : type
You can also give the initial value (otherwise the value defaults to 0 for numbers, "" for strings).
var foo = 123
var bar : string = "qwerty"
Constants always have a value and never use a typename (after ':') because the type is known from the value.
constant TIMEOUT = 300
Syntax for Modules
module name
{
.....declarations here.....
}
Syntax for functions
Ordinary functions use the following syntax. The return type (and the ':') is optional, when omitted then the function does not return any value, like void functions in C. Note too the equals sign before the function body, which is compulsory.
function name(arguments....) : type =
{
.....code here.....
}
Native functions are implemented by the host environment (EDGE) , and hence you cannot add your own. For completeness their syntax looks like this:
function name(arguments....) : type = native
The original thread can be found here:COAL on the EDGE forums.
COAL (HUD Script) - Explanation
COAL (HUD Script) - Explanation
\(סּںסּَ` )/ۜ
Re: COAL (HUD Script) - Explanation
I never had it out for COAL ,I'm sure it works well and has advantages. One of the great things about 3dge was its greater compatibility with older versions like 1.29 and such. It's probably not technically possible, but having Coal and lua side by side would make for less incompatibility.
just a thought.
-Z
just a thought.
-Z
The banlist has been updated successfully.
Re: COAL (HUD Script) - Explanation
Or a sort of conversion utility, I suppose, would work. Maybe a small app that turns a normal LUA func into an equivalent COAL func...
\(סּںסּَ` )/ۜ