COAL manual WIP

Discuss anything EDGE-related that doesn't fall into the categories.

Moderators: andrewj, Corbin, Lobo

User avatar
andrewj
Posts: 698
Joined: Sat 05 May 2007 11:22 am
Location: Tasmania

COAL manual WIP

Postby andrewj » Wed 16 Sep 2009 9:05 am

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
Last edited by andrewj on Thu 03 Dec 2009 1:49 pm, edited 12 times in total.

User avatar
Dartmerc
Posts: 570
Joined: Tue 21 Aug 2007 3:25 am
Location: Sydney
Contact:

Postby Dartmerc » Thu 17 Sep 2009 5:05 am

Probably somewhat offtopic - will we have any additional control over the automap with coal? Like, can we choose to display enemies.. and have control over when to disable/enable their visibility?

User avatar
Karnizero
Posts: 370
Joined: Sun 08 Mar 2009 2:45 am
Location: Espa

Postby Karnizero » Thu 17 Sep 2009 4:01 pm


User avatar
andrewj
Posts: 698
Joined: Sat 05 May 2007 11:22 am
Location: Tasmania

Postby andrewj » Fri 18 Sep 2009 12:26 pm


User avatar
Dartmerc
Posts: 570
Joined: Tue 21 Aug 2007 3:25 am
Location: Sydney
Contact:

Postby Dartmerc » Thu 26 Nov 2009 1:21 pm

Andrew, what is the syntax for create arrays within Coal?

User avatar
andrewj
Posts: 698
Joined: Sat 05 May 2007 11:22 am
Location: Tasmania

Postby andrewj » Fri 27 Nov 2009 4:53 am

Coal does not support arrays.

User avatar
Dartmerc
Posts: 570
Joined: Tue 21 Aug 2007 3:25 am
Location: Sydney
Contact:

Postby Dartmerc » Fri 27 Nov 2009 5:09 am

That makes me sad

User avatar
andrewj
Posts: 698
Joined: Sat 05 May 2007 11:22 am
Location: Tasmania

Postby andrewj » Fri 27 Nov 2009 5:13 am

me too.

P.S. updated the docs some with information on Operators.

User avatar
Karnizero
Posts: 370
Joined: Sun 08 Mar 2009 2:45 am
Location: Espa

Postby Karnizero » Wed 02 Dec 2009 10:07 pm


User avatar
andrewj
Posts: 698
Joined: Sat 05 May 2007 11:22 am
Location: Tasmania

Postby andrewj » Thu 03 Dec 2009 1:43 pm


User avatar
Karnizero
Posts: 370
Joined: Sun 08 Mar 2009 2:45 am
Location: Espa

Postby Karnizero » Thu 03 Dec 2009 3:25 pm


User avatar
Karnizero
Posts: 370
Joined: Sun 08 Mar 2009 2:45 am
Location: Espa

Postby Karnizero » Thu 11 Feb 2010 6:01 pm

Can I add the COAL_API.ec to my PWAD, as can i do with COAL_HUD?


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests