We might need some custom syntax highlighting here
-.. code-block:: inform6
+.. code-block:: inform
statement;
Our games have used these statements, about half of the Inform
possibilities:
-.. code-block:: inform6
+.. code-block:: inform
give obj_id attribute;
give obj_id attribute attribute ... attribute;
Although our example games haven't needed to use them, these looping
statements are sometimes useful:
-.. code-block:: inform6
+.. code-block:: inform
break;
continue;
hold for now; they're not immediately relevant to everyday code and have
mostly to do with printing and formatting:
-.. code-block:: inform6
+.. code-block:: inform
box
font
In particular, avoid using the deprecated jump statement if you possibly can.
-
-..rubric:: Print rules
+.. rubric:: Print rules
In ``print`` and ``print_ret`` statements, each ``value`` can be:
* a print rule. You can create your own, or use a standard one, including:
-
.. tabularcolumns:: ll
+-------------------------+---------------------------------------------------+
``Object`` and ``Verb`` the full supported syntax is more sophisticated
than the basic form presented here:
-.. code-block:: inform6
+.. code-block:: inform
Class class_id
with property value,
There's only a handful of useful directives which we haven't needed to
use:
-.. code-block:: inform6
+.. code-block:: inform
Attribute attribute;
but there's a whole load which are of fairly low importance for now:
-.. code-block:: inform6
+.. code-block:: inform
Abbreviate
Array
You can create and initialise a property in an object's ``with`` segment:
-.. code-block:: inform6
+.. code-block:: inform
property, ! set to zero / false
In each case, the ``value`` is either a compile-time ``expression``, or
an embedded routine:
-.. code-block:: inform6
+.. code-block:: inform
property expression,
You can refer to the value of a property:
-.. code-block:: inform6
+.. code-block:: inform
self.property ! only within that same object
and you can test whether an object definition includes a given property:
-.. code-block:: inform6
+.. code-block:: inform
(obj_id provides property) ! is true or false
Standalone routines are defined like this:
-.. code-block:: inform6
+.. code-block:: inform
[ routine_id; statement; statement; ... statement; ];
and called like this:
-.. code-block:: inform6
+.. code-block:: inform
routine_id()
These are embedded as the value of an object's property:
-.. code-block:: inform6
+.. code-block:: inform
property [; statement; statement; ... statement; ],
and are usually called automatically by the library, or manually by:
-.. code-block:: inform6
+.. code-block:: inform
self.property() ! only within that same object
are automatically initialised to zero every time that the routine is
called:
-.. code-block:: inform6
+.. code-block:: inform
[ routine_id var_id var_id ... var_id; statement; statement; ... statement; ];
is simply to initialise the matching local variables to the argument
values rather than to zero:
-.. code-block:: inform6
+.. code-block:: inform
routine_id(expression, expression, ... expression)
Every routine returns a single value, which is supplied either
explicitly by some form of return statement:
-.. code-block:: inform6
+.. code-block:: inform
[ routine_id; statement; statement; ... return expr; ]; ! returns expr
``statements`` is one -- ``return``, ``print_ret``, ``"..."` or
``<<...>>`` -- that causes an explicit return, then:
-.. code-block:: inform6
+.. code-block:: inform
[ routine_id; statement; statement; ... statement; ];
returns ``true`` and
-.. code-block:: inform6
+.. code-block:: inform
property [; statement; statement; ... statement; ]
Here's an example standalone routine which returns the larger of its two
argument values:
-.. code-block:: inform6
+.. code-block:: inform
[ Max a b; if (a > b) return a; else return b; ];
and here are some examples of its use (note that the first example,
though legal, does nothing useful whatsoever):
-.. code-block:: inform6
+.. code-block:: inform
Max(x,y);
require the functionality which the routine provides. We've mentioned
these library routines:
-.. code-block:: inform6
+.. code-block:: inform
IndirectlyContains(parent_obj_id, obj_id)
in your source file, in which case the library calls it at an
appropriate time. We've mentioned these optional entry point routines:
-.. code-block:: inform6
+.. code-block:: inform
DeathMessage()
And this, the only mandatory one:
-.. code-block:: inform6
+.. code-block:: inform
Initialise()
with the rest of the community. This example, with the name changed, is
from a file in the Archive:
-.. code-block:: inform6
+.. code-block:: inform
[xxxx i j;
if (j==0) rtrue;
more comprehensible; we haven't actually tested that it (still) works,
though that second ``else`` looks suspicious:
-.. code-block:: inform6
+.. code-block:: inform
[ xxxx i j;
if (i in player || i has static or scenery || j == nothing) return true;
* These five lines all do the same thing:
- .. code-block:: inform6
+ .. code-block:: inform
return true;
return 1;
* These four lines all do the same thing:
- .. code-block:: inform6
+ .. code-block:: inform
return false;
return 0;
* These four lines all do the same thing:
- .. code-block:: inform6
+ .. code-block:: inform
print "string"; new_line; return true;
print "string^"; return true;
* These lines are the same:
- .. code-block:: inform6
+ .. code-block:: inform
print value1; print value2; print value3;
print value1, value2, value3;
* These lines are the same:
- .. code-block:: inform6
+ .. code-block:: inform
<action noun second>; return true;
<<action noun second>>;
* These lines are also the same:
- .. code-block:: inform6
+ .. code-block:: inform
print "^";
new_line;
* These ``if`` statements are equivalent:
- .. code-block:: inform6
+ .. code-block:: inform
if (MyVar == 1 || MyVar == 3 || MyVar == 7) ...
* These ``if`` statements are equivalent as well:
- .. code-block:: inform6
+ .. code-block:: inform
if (MyVar ~= 1 && MyVar ~= 3 && MyVar ~= 7) ...
if (MyVar ~= 1 or 3 or 7) ...
expression; all that matters is its value: zero (false) or anything
else (true). For example, these statements are equivalent:
- .. code-block:: inform6
+ .. code-block:: inform
if (MyVar ~= false) ...
if (~~(MyVar == false)) ...
contains ``true`` (1), *not* whether its value is anything other than
zero.
- .. code-block:: inform6
+ .. code-block:: inform
if (MyVar == true) ...
``++MyVar;`` work the same as ``MyVar = MyVar + 1;`` For example,
these lines are equivalent:
- .. code-block:: inform6
+ .. code-block:: inform
MyVar = MyVar + 1; if (MyVar == 3) ...
if (++MyVar == 3) ...
cases the value of ``MyVar`` afterwards is 3. As another example,
this code (from Helga in "William Tell"):
- .. code-block:: inform6
+ .. code-block:: inform
Talk: self.times_spoken_to = self.times_spoken_to + 1;
switch (self.times_spoken_to) {
could have been written more succinctly like this:
- .. code-block:: inform6
+ .. code-block:: inform
Talk: switch (++self.times_spoken_to) {
1: score++;
* Similarly, the statements ``MyVar--;`` and ``--MyVar;`` work the same
as ``MyVar = MyVar - 1;`` Again, these lines are equivalent:
- .. code-block:: inform6
+ .. code-block:: inform
MyVar = MyVar - 1; if (MyVar == 7) ...
if (--MyVar == 7) ...
``phrase_matched`` attribute). To create them, you would use these
directives near the start of your source file:
-.. code-block:: inform6
+.. code-block:: inform
Attribute attribute;
their placement at the start of the game, we're left with object
definitions starting like this:
-.. code-block:: inform6
+.. code-block:: inform
Room street "A street in Altdorf"
same object tree, using "arrows". That is, we could have defined those
parent-and-child objects as:
-.. code-block:: inform6
+.. code-block:: inform
Room below_square "Further along the street"
Furniture -> stall "fruit and vegetable stall"
potatoes and the other fruit and vegetables where actually *on* the
stall. Then we might have used:
-.. code-block:: inform6
+.. code-block:: inform
Room below_square "Further along the street"
Furniture -> stall "fruit and vegetable stall"
distinction: you can use double quotes in name properties and Verb
directives:
-.. code-block:: inform6
+.. code-block:: inform
NPC stallholder "Helga" below_square
with name "stallholder" "greengrocer" "monger" "shopkeeper" "merchant"