Contents

Zita
Zita is a text adventure engine written in Python. Text adventures, also known as interactive fiction in some cases, challenge the minds of people, using no graphics at all. With Zita, it is now possible to write a text adventure in normal Python syntax.
Installation
To run Zita, Python must be installed. No other depencies are needed.
To run Zita, run zita.py. If a game directory is specified, Zita will attempt to execute the game files in that directory. If no game directory is specified, Zita will attempt to run the game Zeqy. Besides zita.py, there is also a file named defs.py. This file is executed by zita.py on startup and should not be used on its own. It contains functions crucial to Zita.
Hacking
Zita is released under the GPLv3+. Feel free to improve it.
Zeqy
Zeqy is a very short text adventure developed for Zita and is shipped together with the engine. It features a short "story" and proves Zita's simplicity. Zeqy is released under the Creative Commons Zero 1.0 Universal license. This means that you're free to do whatever you want to do with Zeqy. There is no owner of Zeqy.
Loading data
Games to be run in Zita's engine are saved in text files in a directory. In the case of Zeqy, several files reside in the 'zeqy' directory. The files of a game directory are loaded when Zita runs. In this section, Zeqy will be used as an example of how Zita works.
A look at the 'zeqy' directory reveals the following files:
commands.zt functions.zt LICENSE rooms.zt defaults.zt items.zt main.zt vars.zt
When Zita starts, it first looks for a file named 'prerun' inside the game directory. If a file named that is found, Zita will execute any Python code inside the file. This allows programmers to change various default values. After looking for 'prerun', Zita attempts to find a main file. By default, the main file must be named something that starts with 'main', though this can be changed in the 'prerun' file. If several files that have names starting with 'main' exist, only one of them will be used. If, for example, a directory has both a file named 'main', a file named 'main.py' and a file named 'main.zt', the latter will be loaded (except if the 'prerun' file states otherwise). This is because the '.zt' ending is the default suffix.
Looking at the file list earlier, it is now possible to deduct that the file 'main.zt' must be the main file for Zeqy. Here it is:
| |
Python code in the main file is executed before Zita starts a game. This means that the main file is suitable to use to print a welcome message, though this is of course also possible to do in the 'prerun' file.<br /> What should be done in the main file and not in the 'prerun' file is including files. The include function loads and executes both files and files in subdirectories. In the above example, only files are imported, as no subdirectories exist. If, however, such directories did exist, the include command would look for those too.
An example
We have a game directory with a file named 'stuff' and a directory named 'stuff' that holds several files. In the main file we write this:
| |
This makes Zita load and execute both the 'stuff' file and the files in the 'stuff' folder.
It is possible to make the include function accept only either one file, all files or files in subdirectories. Refer to the include and getfilenames functions found in defs.py.
When Zita has succesfully loaded all data that it needs to run a game succesfully, it is important to use the goto function to create a starting position. A starting position can also be defined in another way, but using goto ensures that a message describing the current location is shown.
Data structures
When the main file has been loaded and executed, an infinite loop is started. It runs until the variable COMPLETELY_DONE is true. When that happens, Zita exits.
The code inside the loop asks the user for input, which it the processes. Input is split with spaces, and the first word is always the command. A command cannot exist of more than one word. All characters that come after the command are considered part of an object. After the user has pressed Enter, Zita searches through several global variables to see if what the user has typed matches a stored command and/or an object.
The 6 important global variables in Zita are:
roomitemvarcommanddefaultextra
All except extra are dictionaries. The extra variable is a string that can contain Python code.
>room
This variable keeps track of the "rooms" in a game. Rooms are the locations in which a player can be. Rooms can hold items and point to other rooms. See the commented example below containing the room (taken from Zeqy's 'rooms.zt'):
| |
Note that in the above code, the variable citem pops up. This is a special variable holding the current item id. In the items list above, in the case of 'redflower', citem would be short for 'redflower', and in the case of 'multic_flower', citem would be short for 'multic_flower'. This may seem useless, but in some cases it's handy. Read on.
>item
This variable keeps information about items. Items can be carried around in an inventory. An item has a name and a series of commands associated with it. An item can have two states. Either it's in or it's out, i.e. it's either in the inventory or in the current room. See below for a commented example (taken from Zeqy's 'items.zt'):
| |
The above example presents only a simple item. It is possible to create much more complex ones. A slightly more complex item can be seen below (this one is also taken from 'items.zt'):
| |
Last, but not least, Zita understands the 'pref' (prefix) property:
| |
If Zita detects more than one item matching the user's input, the user is prompted to choose between the available items. This would be the case if a room had to books, a red one and a green one, and the user merely states the lust to read a book.
Tip: If you get tired of typing long item names, you can choose to only type the last part of an item. Instead of typing 'capture magenta-coloured space creep', you can choose to simply type 'capture creep' or even 'capture p' (as the last letter in 'capture magenta-coloured space creep' is a p).
>var
This variable merely holds variables and their respective values. var variables can be used to store data. Looking at 'vars.zt' from Zeqy, we see, among other stuff, this (commented version):
| |
Variables are useful.
>command
If Zita is unable to match a user-typed command with a user-typed object, it checks if a command independent of items matches. A command can be short ones such as:
| |
..Though it can also include more complex commands, such as:
| |
If no available item has a command named 'go', the above code will be executed in the case of a 'go' request. Typing 'go s', 'go west' and other variations can, however, end up being annoying (if you're lazy), so adding 's', 'west' and similar shortcut commands would easen playing a game. This can be done in the following way:
| |
Item-independent commands can also be used to make people laugh.
>default
The default variable contains info on what to do when commands don't seem to exist. For example, it's tiresome to insert a 'get' commands in ever item we create. By using the default variable, we can create an item definition which acts as a shortcut. See below:
| |
Using defaults thereby make programming text adventures in Zita much easier.
>extra
Let's have another look at the zeqy directory:
commands.ztfunctions.zt LICENSErooms.ztdefaults.ztitems.ztmain.ztvars.zt
The only file we haven't had a look in is the 'functions.zt' file (LICENSE does not include Python code). The functions file contains.. functions. And global ones at that.
| Title: | Zita |
| Modified: | Fri, 13 Jan 2012 22:06:46 +0100 |
| Created: | Tue, 02 Aug 2011 23:08:13 +0200 |
| Revision: | 2 (local), 53 (global) |
| Summary: | A simple but cumbersome text adventure game engine |
| License: | Creative Commons Attribution-ShareAlike 3.0 Unported (or any later version) (page) |
| License: | GNU General Public License, version 3 (or any later version) (program) |
| License: | Creative Commons Zero 1.0 Universal (or any later version) (Zeqy) |