ZZT-OOP/Syntax

From Wikibooks, open books for an open world
Jump to: navigation, search

ZZT-OOP has a very simple syntax, as demonstrated by the following example:

@Fred
'Objects run their programs right away;
'the following command will temporarily
'halt program execution.
#end
:touch
$This is an object named Fred!
!move;Tell Fred to move around.
#end
:move
/rndp rndne/rndp rndne
?n?n?n?n?s?s?s?s
FRED: I moved around!

The first character of each statement determines how the rest of the line is treated. For example, the first line begins with the "at" symbol (@), which makes it a name; the second line begins with an apostrophe, which makes it a comment, etc... Our discussion of ZZT-OOP syntax continues with a list of all the possible starting characters and their effects.

' (Comment)[edit]

This is a comment, it does nothing but inform you or whoever looks at your code what a function does. If you have a very large file (>320KB), get rid of any of these you may have (not including ones used as zapped labels). Also: this statement isn't a comment in fact, but a pre-zapped label (that means you can jump to it only after you restored it)

(Text), $(Text)[edit]

This prints a line of text at the bottom of the screen, or if there is more than one line, print a scroll. Using $(Text) prints text in a scroll centred and in white.

:(Label)[edit]

This is a label. You can jump to labels. Yes. You can also make other programs jump to labels.

!(Label);(Text)[edit]

This prints a line of text in a scroll in white with a pink arrow as a bulletpoint. This is an option. Selecting it will call the label given.

@ (Object Name)[edit]

The "@" character indicates that the rest of the line is the object's name. In the example above, the line @Fred gives the object the name "Fred." The only limit on object names is that they must be stated on the first line of the program; "@" statements elsewhere in the file are ignored.

If a named object opens a text box, the object's name appears at the top of the textbox, replacing the generic title "Interaction." It is not necessary to give an object a name.

# (Generic Command)[edit]

The "#" character indicates a command, or a jump to a label. For example, the example program uses the command #end to stop program execution. Many other commands exist; they will be discussed in detail in the next couple of chapters. For now, it is good enough to know what they look like.

/ and ? (Movement)[edit]

The "/" character instructs the object to move. The direction that the object moves is indicated by the text that follows; for example, /n causes the object to move one space to the north (move up one space). When "/" is used and the object cannot move in the specified direction, the object will simply wait until it can move in that direction; this results in the object waiting forever if it is facing something that does not move, such as a wall. The "?" character works like "/", but with one difference: "?" movement commands will be ignored if the object cannot move in the specified direction.

Both "?" and "/" are unique because they can be "stacked"; this means that a movement instruction can be followed by another statement. For instance, in the example program, you saw the code ?n?n?n?n?s?s?s?s. When this code runs, the movement instructions will be followed from left to right; the object will try to move four spaces upward, then four spaces downward. Types of statement can be mixed; for example, it is perfectly alright to say /n?n?n/n or even /n/n/s/s#end. However, you cannot stack a statement onto a non-movement statement. That is to say, /n/s/e/w#end is valid ZZT-OOP, but /n/s/e/w#end/n is not.