WelcomeWhat's NewsORLibraryDownloadsLinksWebMaster@OnyxRing.com

This site
produced
656719
pageviews since
8/19/2004

Today's date:
11/20/2017






Author: Roger Firth
Title: REPLAYing command scripts

Creation Date: 8/6/2004 10:38:26 PM
Last Updated: 8/6/2004 10:38:26 PM


REPLAYing command scripts

A game's development process involves a great deal of highly-focused testing. As you create each new room, object, NPC, verb and so on, you give it lots and lots of exercise, both to confirm that it does what it's supposed to, and to ensure that it doesn't fail in unusual circumstances. Doing this carefully as you go along is common sense: it's much easier to thrash the hell out of some new code while you can still clearly remember just how you intended it to behave.

As the game grows, it becomes harder and harder to check it thoroughly. Sure, it's still easy to test the new stuff: the problem is regression testing, verifying that what you've just done hasn't broken what you did yesterday, or last week, or last month...

One excellent way of minimizing the hassle is to create command scripts which you can replay to ensure that the whole game still hangs together after each set of changes. Inform includes the verbs RECORDING ON and RECORDING OFF which create a script by capturing commands as you type them, and REPLAY which reruns (some or all of) a game by reading commands from a script file. These verbs are described in §7.1 of the Inform Designer's Manual (Edition 4/1).

RECORDING and REPLAY are available only when debugging is enabled, which isn't normally a problem while you're developing: Strict mode (and thence Debug mode) is the default compiler setting. However, when you release a game to beta testers, as a competition entry, or simply for general enjoyment, you'll want to turn off Debug mode -- by compiling with the -~S flag -- in order to prevent unscrupulous cheating. This means that these verbs now don't work; a bit annoying, since you'd really like to REPLAY your regression tests in regular mode as well as in Debug mode.

Here's the very simple way to make RECORDING and (especially) REPLAY available at all times. In addition, it also implements ! as a comment verb, so that you can embed remarks in your script files to remind yourself of what's being tested. Just add this code to the end of your game, after the Include "Grammar"; line:

#Ifndef DEBUG;
Global    xcommsdir;

[ CommandsOnSub;
    @output_stream 4; xcommsdir = 1; "[Command recording on.]";
    ];
[ CommandsOffSub;
    if (xcommsdir == 1) @output_stream -4;
    xcommsdir = 0; "[Command recording off.]";
    ];
[ CommandsReadSub;
    @input_stream 1; xcommsdir = 2; "[Replaying commands.]";
    ];

Verb meta 'recording'
    *       -> CommandsOn
    * 'on'  -> CommandsOn
    * 'off' -> CommandsOff;
Verb meta 'replay'
    *       -> CommandsRead;
#Endif;

[ CommentSub; ];
Verb meta '!'
    *       -> Comment
    * topic -> Comment;

In fact, you might find it convenient to place the code in a file Replay.h which you can then easily Include in all of your games. Finally, by way of example, here's a script file which exercises my example game "Cloak of Darkness":

! Command script to exercise "Cloak of Darkness" (Cloak.inf)
!
! NORTH goes nowhere
NORTH
!
! SOUTH is dark, and you need to come straight out again
SOUTH
NORTH
!
! Inspect your possessions
EXAMINE ME
INV
EXAMINE CLOAK
TAKE OFF CLOAK
DROP IT
!
! Investigate the Cloakroom
WEST
EXAMINE HOOK
TAKE IT
HANG CLOAK ON HOOK
TAKE CLOAK
HANG IT ON HOOK
EXAMINE HOOK
EAST
!
! Now OK to enter the Bar
SOUTH
TAKE MESSAGE
READ MESSAGE



Copyright 2004 - 2017 : Roger Firth
OnyxRing.com has been given the potentially non-exclusive right to display the content of this article. However the original author retains all rights. Permission to reproduce this article -- either in part or in whole -- is left strictly to the discretion of the original author.

Table of ContentsAuthorsSearchIndex
Would you
recommend this
article to
someone else?
You bet I would! Heck No!