RAL: Basic Concepts & The CAOS Command Line
This article was imported from the RAL manual. However, it's about CAOS generally.
Contents
Opening
be calm, little norn — I merely control your universe
So, you’ve just got Docking Station. You want to start typing some CAOS so you can see how it works.
Very well. Start Docking Station, create a new world, and don’t spawn in any creatures (they’ll be distracting right now).
Press Control-Shift-C. This opens the CAOS Command Line.
CAOS Command Line Warning! You can damage your world with this utility. Press Shift+Ctrl+C to close it now. >
The CAOS Command Line.
Here, you can type any CAOS that does not contain asynchronous commands. Asynchronous (aka blocking) commands are those commands that take more than one frame (1/50th of a second) to execute.
What Are Commands?
All CAOS is made up of a list of commands.
Here’s some example commands to try in the command line, with their output:
> outv 1 1 > outs "Hello!" Hello! > outs "Hello, " outv 12 Hello, 12
The first command, outv
, writes a number to the output stream.
outs
, on the other hand, writes a string (a sequence of text) to the output stream (here, the CAOS Command Line itself).
In the second line, "Hello!" is put in, and Hello!
comes out.
In the third line, two commands are on the same line, running outs
and then outv
.
CAOS only cares about newlines in relation to comments. However, the CAOS Command Line differs somewhat in that pressing Enter executes the line immediately, and therefore a line must contain a complete command or series of commands.
What Are Expressions?
> outs modu OriginalDisplay DirectX (netbabel 148)
modu
is put in, and OriginalDisplay DirectX (netbabel 148)
comes out.
What’s up with that? The answer: Expressions.
In most cases in CAOS, a constant value (a number, a string, or null) may be substituted for an CAOS Expression, which is a sequence which provides a value of the same kind (number, string, agent reference).
(We’ll get to what agent references are later, as part of Scripts And A Talking Lemon.)
Expressions are not made up of commands. They are a separate set of symbols, although there is some overlap in the names sometimes.
Furthermore, in rare cases, the kind of expression expected (that is, if a number, a string, or an agent reference is expected) changes the meaning of the symbol.
> outs modu OriginalDisplay DirectX (netbabel 148)
Here, we see the command outs
, which expects a string, being passed the expression modu
, which provides a string describing details of how the engine was built. (For example, some users may see SDL in this line rather than DirectX.)
Expressions in CAOS are not particularly advanced. In particular, while it is possible to put expressions within expressions in some cases, there is no way to perform addition, subtraction, and so forth inline within an expression.
> outs subs modu 1 8 Original
Here, outs
is being passed the string expression subs modu 1 8
. The output of this expression is "Original", which is then output.
What Are Variables?
> setv va00 6 mulv va00 7 outv va00 42
This is an example of the use of variables, specifically va00
.
The VAxx variables — va00
through va99
— can store any values during the execution of a script. Unfortunately, the CAOS Command Line loses the contents of all variables between lines (because it executes those lines immediately), so the example had to be written all in one line.
These variables start set to the number 0.
Breaking the example down into its components, there are:
setv va00 6
- Sets
va00
to 6.
- Sets
mulv va00 7
- Multiplies
va00
by 7:va00
is now 42.
- Multiplies
outv va00
- Outputs
va00
.
- Outputs
setv
is a command that writes a number into a variable, alongside it’s counterparts seta (agent reference) and sets (string).
mulv
is a command that multiplies a variable by some expression. Similarly, addv
, subv
, and divv
exist, to add, subtract, and divide respectively.
It is important to note two things:
- These variables can hold any value of the kinds described above — numbers, strings, and agent references.
- Variables are expressions, but not all expressions are variables.
Things To Check
You should attempt to write a complex mathematical expression as a list of CAOS commands.
A particularly good one is this:
((5 + 6) * (7 + 4)) / 2 = 60
Conventional wisdom would say the answer to this is either 60.5 or 60 remainder 1. The answer in CAOS is that it depends on if you suffix your numbers with .0 at the end — this makes them "floating-point", and thus capable of representing fractional values. "Float-ness" spreads through expressions automatically, but if both sides of a division are integer, then an integer division is performed, and the remainder is lost.
Importantly, your solution should only use the numbers 5, 6, 7, 4, and 2 — you must not simply write outv 60
and call that a solution.