Inform 7 Home Page / Documentation
§27.19. Longer extracts of Inform 6 code
Whole routines, object and class definitions (or any other directives) can be pasted in wholesale using sentences like so:
[ ExtraFunction a b; return a*b; ];
Such inclusions are pasted into the final compiled code at the end of the file, after the I6 grammar has been declared.
In such extracts, we sometimes need to refer to objects, variables or values which can't be described using I6: or rather, which can be described, but we don't know how. To this end, any text in an inclusion written in "(+" and "+)" parentheses is treated as an I7 value, and compiled accordingly, with all type-checking waived for the occasion. For instance:
Global my_global = (+ the tartan rucksack +);
Here "the tartan rucksack" is translated into "O18_tartan_rucksack", or something similar: the I6 object created to represent the rucksack. Thus the actual line of code produced is
Global my_global = O18_tartan_rucksack;
The material between "(+" and "+)" is generally treated as a value, and thus compiles to the I6 form of that value. But it could also be a property name, which compiles to the I6 form in question, or a defined adjective, which compiles to the name of the routine to call which tests whether that adjective is true.
Three warnings. The material in "(-" and "-)" is called template code, and it is not quite treated as literal. That means certain characters cause Inform to react:
1. Beware of accidental "(+" usage - for instance,
[ MyCleverLoop i; for (++i; i<10; i++) print i; ];
looks reasonable, but contains "(+" and "+)". Spaces around the first "++" would have been enough to avoid this one; "+)" is only significant where it follows a "(+".
2. Beware of placing an "@" character in the first column, that is, immediately following a new line. (In template code this marks off paragraph divisions.) So for instance,
[ Set_Stream ret;
@glk 67 ret;
is tripped up by the Glulx assembly language opcode "@glk" because this occurs in column 1. Indenting it with a little space or a tab is enough to avoid the problem.
3. Be careful if you're creating an I6 variable holding initialised I7 text. For example,
Global saved_optional_prompt = (+ "!!>" +);
looks as if it will work, but doesn't, for reference-counting reasons we needn't go into; instead you need
Array sop_storage --> PACKED_TEXT_STORAGE "!!>";
Global saved_optional_prompt = sop_storage;
But it's far better to avoid initialising text variables from I6 entirely. The same problems arise with constant lists.
|Start of Chapter 27: Extensions|
|Back to §27.18. Making and testing use options|
|Onward to §27.20. Primitive Inform 6 declarations of rules|
Status line with centered text, the hard way
Making major changes to display features, such as the construction of the status line, sometimes requires that we rely on Inform 6 in bulk; here is how we might produce the Trinity-style status line, with the location centered at the top center of the screen.
[ PrintCenteredStatus i j;
@set_cursor 1 0;
i = 0->33;
@output_stream 3 printed_text;
print (name) location;
j = (i - (printed_text-->0))/2;
@set_cursor 1 j;
print (name) location;
In fact, as we've already seen, many extra modifications to the display behavior are possible using Basic Screen Effects.