Using Libraries

Introduction

Sometimes you might come up with some useful ASL code that would be useful in all of your games and maybe handy to other game authors. In this case, you'll want to create a library - then you'll be able to reuse it in any game you make, and perhaps distribute it to other people so they can use it in theirs.

A library is similar to a normal ASL file in that it consists of "define" blocks, containing procedures or even rooms and selection blocks. This is then usually saved as a .lib file, and it can then be included in any game simply by adding a line like this:

!include <mylibrary.lib>

to the game's ASL file. All included libraries then basically become part of the game file, and their procedures and rooms can be called in just the same way as if they were part of the game's own code.

You can also include other libraries from within libraries, using the normal !include statement. Quest will not add the same library twice to a game, so it is quite safe to include any popular library from within your library if it requires it, without needing to worry about whether any other library or the game itself will include it.

All libraries must begin with these lines:

!library
!asl-version <400>

These tell Quest that the file is a valid library. The !library must be on the very first line - !asl-version can appear anywhere in the file.

!addto blocks

Sometimes with a library, you'll want to add some lines that will be included as though they were part of the game's "define game" block - for example, you might want your library to add a startscript to the game, or to add some commands or verbs. If this is the case, you need to use an !addto block. Enclose the lines with:

!addto game

at the beginning, and

!end

at the end. (If you merely included your own define game block in the library, this would be separate to the game's own game definition block - and would therefore be ignored). All !addto blocks follow this basic form.

When you use !addto game, you can include a startscript. This will be executed before any startscript specified by the main game ASL file.

Similarly, to add synonyms to a library, enclose the lines to add with:

!addto synonyms

and

!end

A game can add properties and actions to the default and defaultroom types using !addto type <default> and !addto type <defaultroom> blocks.

Creating Libraries for QDK Users

Libraries can add interface elements to QDK, for authors using QDK. This makes it much easier for game authors using QDK to use your library. See QDK Library Interfacing for information.

Example:

!library
!asl-version <400>

!addto game
	verb <eat> msg <You can't eat that.>
!end

!addto synonyms
	consume; munch = eat
!end

define procedure <multiprint>
	for <i; 1; $parameter(2)$> msg <$parameter(1)$>
end define

This adds "EAT", "CONSUME" and "MUNCH" commands to a game, and adds a "multiprint" procedure, which would print out its first parameter the number of times specified by its second parameter.

 

< Back