ZZT-oop
Encyclopedia
ZZT-oop was an early in-game scripting
Scripting language
A scripting language, script language, or extension language is a programming language that allows control of one or more applications. "Scripts" are distinct from the core code of the application, as they are usually written in a different language and are often created or at least modified by the...

 programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

, designed by Tim Sweeney
Tim Sweeney (game developer)
Tim Sweeney, born in 1970, is a computer game programmer and the founder of Epic Games, being best known for his work on ZZT and the Unreal Engine....

, for his computer game ZZT
ZZT
ZZT is an ANSI character-based computer game, created in 1991 by Tim Sweeney of Epic Games , who later designed Unreal. It remains a popular DOS game creation system. ZZT itself is not an acronym for anything; its title was simply chosen so it would always appear at the very bottom of newsgroup...

. The name stands for ZZT Object Oriented Programming language. The name of the language is a play on ZZ Top
ZZ Top
ZZ Top is an American rock band, sometimes referred to as "That Little Ol' Band from Texas". Their style, which is rooted in blues-based boogie rock, has come to incorporate elements of arena, southern, and boogie rock. The band, from Houston Texas, formed in 1969...

, an American rock band.

Overview

ZZT-oop is event-driven
Event-driven programming
In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

. A ZZT game is composed of a set of objects, each of which has an attached script. Scripts are executed concurrently
Concurrency (computer science)
In computer science, concurrency is a property of systems in which several computations are executing simultaneously, and potentially interacting with each other...

 (one command being taken in turn from each script running on the current screen), and objects communicate by passing messages
Message passing
Message passing in computer science is a form of communication used in parallel computing, object-oriented programming, and interprocess communication. In this model, processes or objects can send and receive messages to other processes...

 to one another.

Shortcomings

The ZZT-oop language is limited in application. It was designed for simplicity rather than flexibility. Boolean flags are the only kind of variables, making arithmetic quite difficult; the programmer is forced to be creative with algorithms, often relying on physical movement, possibly in invisible (but still physically present) objects, rather than arithmetic calculations.

Although ZZT-oop calls itself "object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

", objects are not instantiable due to their physical nature, meaning that one needs to duplicate much code to create complex systems.

ZZT-oop also lacks functions, and routines are likely to be interrupted by rogue messages — including ones sent by the object itself when it is shot or touched — and never completed. It is possible to overcome this disadvantage in a crude manner by using state flags or the lock and unlock commands during important routines; however, this is likely to cause the object to miss out on signals.

ZZT-oop is wholly run-time interpreted with no pre-parsing. No lexical analysis
Lexical analysis
In computer science, lexical analysis is the process of converting a sequence of characters into a sequence of tokens. A program or function which performs lexical analysis is called a lexical analyzer, lexer or scanner...

 is performed before running, nor is any byte code translation applied. This means that any errors are reported in a cryptic way during run-time, and this can make debugging time consuming.

ZZT was intended for creating adventure game
Adventure game
An adventure game is a video game in which the player assumes the role of protagonist in an interactive story driven by exploration and puzzle-solving instead of physical challenge. The genre's focus on story allows it to draw heavily from other narrative-based media such as literature and film,...

s with multiple "boards" (that is, locations), but ZZT-oop does not have any way of creating state that persists from one board to the next, with the exception of boolean variables. A board's objects are only accessible while the player is on that board, and pause on board exit until the player reenters.

Strengths

The language has some advantages:
  • ZZT-oop is accessible for beginning programmers. It is simple and intuitive and lacks mathematical operators. This helps beginners to learn the language without frequently needing to consult guides.
  • Integration within the game
    ZZT
    ZZT is an ANSI character-based computer game, created in 1991 by Tim Sweeney of Epic Games , who later designed Unreal. It remains a popular DOS game creation system. ZZT itself is not an acronym for anything; its title was simply chosen so it would always appear at the very bottom of newsgroup...

     makes the language easy to use. Beginners do not need to install multiple programs to start programming. Concrete geographic positions make objects far easier to visualise than with abstract data types.
  • Parallel operating multi-threaded
    Thread (computer science)
    In computer science, a thread of execution is the smallest unit of processing that can be scheduled by an operating system. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process...

     design is easy for one to think about in terms of a dynamic environment

Syntax

The syntax of the language is exceedingly simple. It is line-based, and the first character of each line determines that line's effect.
  • The first line of the program may be prefixed with @, which gives the object a name. Objects without names cannot receive messages from other objects via the #SEND command (except for #SEND ALL:label and #SEND OTHERS:label), since there's no way to refer to them.
  • Unprefixed instructions, or instructions prefixed with $ or !, cause the object to open up a message window and display text to the player.
  • Instructions prefixed with ' indicate comment
    Comment
    A comment is generally a verbal or written remark often related to an added piece of information, or an observation or statement. These are usually marked with an abbreviation, such as "obs." or "N.B."...

    s (really, they are pre-zapped labels).
  • Directions prefixed with / or ? instruct an object to attempt to move in the specified direction. Possible directions include North, South, East, and West, as well as SEEK (to move toward the player) and prefixes such as CW (meaning clockwise
    Clockwise
    Circular motion can occur in two possible directions. A clockwise motion is one that proceeds in the same direction as a clock's hands: from the top to the right, then down and then to the left, and back to the top...

    , such that CW N means east).
  • Messages are similar to the goto statement in declarative languages; the only difference is that they may optionally be sent to another object and cause that other object's own execution path to jump to that point in the script. The points that may be jumped to, called label
    Label (programming language)
    A label in a programming language is a sequence of characters that identifies a location within source code. In most languages labels take the form of an identifier, often followed by a punctuation character . In many high level programming languages the purpose of a label is to act as the...

    s
    , are prefixed with a : and are used to denote both what the name of the message is, and where the object's control should jump when that message is received.
  • Flags are global boolean variables used for conditionals that may only be set or cleared with commands. If the #IF command is called on a given flag variable, then the flag will be evaluated; if it is set to true, the message listed after will be sent, causing the script to jump to that point.
  • Instructions prefixed with # specify commands, which control all interactions with the environment, whether it be shooting, setting a flag, sending a message or processing a conditional. There are dozens of primitive ZZT-oop commands, including
    • #SEND, which sends a message to another object
    • #SET and #CLEAR, which manipulate the values of flags
    • #LOCK, which renders the object deaf to incoming messages, and #UNLOCK, which reverses the operation
    • #PUT, which creates a new object of a specified type and places it next to the current object
    • #BECOME, which causes the current object to become some kind of item or creature, thus ending its programmable lifetime (#DIE acts like #BECOME EMPTY)
    • #ZAP, which replaces the : preceding some label with ' (thus turning the label into a comment), and #RESTORE, which reverses the operation

Example

The program below illustrates a simple "shooter" object that will move back and forth horizontally (east to west), periodically shooting downward (to the south). (If the player is shot, the player will lose health.) If the player touches the shooter, the shooter will be destroyed.

Note the use of an invisible "timer" object to send a periodical ShootDownward message to the Shooter.
The timer's program would normally be attached to an object whose graphical representation was the same as a wall (character
Code page 437
IBM PC or MS-DOS code page 437 is the character set of the original IBM PC. It is also known as CP 437, OEM 437, PC-8, MS-DOS Latin US or sometimes misleadingly referred to as the OEM font, High ASCII or Extended ASCII....

number 219); then, it would go completely unnoticed by the player, since it does not move and turns into a real wall when its program ends.

@Shooter
#GO WEST
:TurnAround
#GO OPP FLOW
:KeepMoving
?FLOW
#IF BLOCKED FLOW THEN TurnAround
#SEND KeepMoving
:Touch
'No need to keep the timer around anymore
#SEND InvisibleTimer:Die
#DIE
:ShootDownward
#SHOOT SOUTH
#SEND KeepMoving

@InvisibleTimer
'The #CYCLE command sets the rate at which this object is updated.
#CYCLE 40
:Loop
#SEND Shooter:ShootDownward
#SEND Loop
:Die
'Turn into a red wall
#BECOME RED SOLID

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK