Boilerplate for ScottKit games: standard actions

After the recent sequence of ScottKit tutorials (building games, rooms and items, actions, occurrences, darkness and light), there remain only two major concepts left to introduce: counters and saved rooms. But before we launch into those, we’ll take a break and look at some standard bits and pieces we’re likely to include in most or all games. We’ll use the same map as last time, since we’re making no major changes:

Put standard actions at the end

Back in the Putting it together section of the actions tutorial, we added actions for three utility verbs to the top of the file: SCORE, INVENTORY and LOOK:

action score: score
action inventory: inventory
action look: look

That wasn’t really right: it would have been better to add them to the end of the file, for two reasons.

First, since the earliest matching action in the file is the one that gets used, by putting these at the top, we removed any chance of modifying the behaviour of these verbs in special circumstances. For example, if we wanted to implement drunkenness, and have the player too confused to recognise what he’s carrying when under the influence, then we could easily do that with a flag — something like:

But that won’t work if we’ve already defined the action for INVENTORY higher up the file: instead, the stock inventory response will always be emitted.

The second reason why it’s better to put standard actions at the bottom of the file is because other actions might share the first few letter of the standard ones. Adams’s own games use three-letter prefixes, so you can abbreviate TAKE HONEY to TAK HON. But that means that INVADE MORDOR is the same INVENTORY MORDOR, which will be matched by the default INVENTORY action.

With that in mind, the standard actions that you’ll probably want to support are those that invoke high-level game-aware instructions. Those are inventory, score, game_over, save_game, and perhaps look (though you don’t need that if you’re going to play your game in a split-screen viewer such as ScottFree.)

(Now that we can examine the sign to see what it says, we no longer need to cumbersome extra-long description.)

Should these be auto-generated?

There is perhaps an argument for the SCORE, INVENTORY, LOOK and SAVE GAME commands to be added automatically to every ScottKit game: after all, there can’t be many games that don’t have them.

But I’ve not done that, for two reasons.

First, there are so few of these, and their definitions are so simple, that it’s truly trivial to copy-paste the actions when they’re needed. This will in general be necessary anyway, so that tweaks can be made — for example, not all games will want the same default message for EXAMINE.

And secondly, this would mean that scottkit -d foo.sao > foo.sck; scottkit -c foo.sck > foo.sao was no longer idempotent: repeated decompile/compile sequences would make the game longer and longer with redundant actions. This seems inherently inelegant. ScottKit is a smallish program that defines a small language for building small games, and one of the appealing aspects of such a system is its explicitness. I prefer No Magic wherever possible.

A standard library?

Should these standard actions, then, be provided as a sort of standard library, distributed with ScottKit, to be included in games only when their authors request them? We might introduce a file-inclusion facility such as %include, and then pull in the standard library using something like %include . (The angle-brackets would mean to include from a well-known location provided by the compiler; double-quotes would look for the named file in the working directory.)

Maybe. But since the standard actions I outlined above only amount to nine lines of code — eleven, if you count the default for examine — I’m not sure it’s worthwhile. That said, I may implement %include for other reasons. It might be nice sometimes to break up a game into multiple files.

Anyway, for now, the approved course is just to copy-paste the standard actions into your game and edit them as you see fit — or indeed write them from scratch.

Putting it together

Here, then, is the complete text of the current version of the game — very similar to the previous version except that it includes the standard boilerplate at the end, a couple of helpful examine actions and a default, and the rum whose drinking impedes the ability to take inventory.

$ scottkit -p t6.sck
ScottKit, a Scott Adams game toolkit in Ruby.
(C) 2010-2017 Mike Taylor <mike@miketaylor.org.uk>
Distributed under the GNU GPL version 2 license,
I'm in a cave mouth
Obvious exits: East.
I can also see: lamp-refilling station
Welcome to the Tutorial adventure.
You must find a gold coin and store it.
Tell me what to do ? e
I'm in a square chamber
Obvious exits: North, East, West.
I can also see: Wooden cross
Tell me what to do ? examine cross
I see nothing special.
Tell me what to do ? n
I'm in a gorgeously decorated throne room
Obvious exits: South.
I can also see: sign, old-fashioned brass lamp
Tell me what to do ? examine sign
It says: leave treasure here, then say SCORE
Tell me what to do ? examine lamp
It is not lit.
Tell me what to do ? get lamp
O.K.
Tell me what to do ? s
I'm in a square chamber
Obvious exits: North, East, West.
I can also see: Wooden cross
Tell me what to do ? get cross
O.K.
Tell me what to do ? e
I can't see. It is too dark!
Tell me what to do ? light lamp
OK, lamp is now lit and will burn for 10 turns.
I'm in a gloomy dungeon
Obvious exits: North, West.
I can also see: Locked door
Tell me what to do ? n
Vampire cowers away from the cross!
I'm in a damp, dismal crypt
Obvious exits: South.
I can also see: Brass key, Vampire
Tell me what to do ? get key
O.K.
Vampire cowers away from the cross!
Tell me what to do ? s
I smell something rotting to the north.
I'm in a gloomy dungeon
Obvious exits: North, West.
I can also see: Locked door
Tell me what to do ? open door
OK
Your light is growing dim.
I smell something rotting to the north.
I'm in a gloomy dungeon
Obvious exits: North, West.
I can also see: Open door leads south
Tell me what to do ? go door
I'm in a dungeon cell
Obvious exits: North.
I can also see: *Gold coin*, bottle of rum
Tell me what to do ? get coin
O.K.
Tell me what to do ? get rum
O.K.
Tell me what to do ? n
I'm in a gloomy dungeon
Obvious exits: North, West.
I can also see: Open door leads south
Tell me what to do ? w
Your light has run out
I'm in a square chamber
Obvious exits: North, East, West.
Tell me what to do ? i
I'm carrying:
*Gold coin* - empty lamp - Wooden cross - Brass key - bottle of rum.
Tell me what to do ? drink rum
OK. I feel funny.
Tell me what to do ? i
I'm carrying ... uh ... you're my best mate, you are.
Tell me what to do ? quit
Did you mean to quit? If so, type QUIT GAME.
Tell me what to do ? quit game
OK, goodbye.
The game is now over.
$

2 responses to “Boilerplate for ScottKit games: standard actions”

Thanks for this. I remember playing Will Crowther’s adventure game back in the early 1970s and being fascinated. The FORTRAN code was clever, but rather complex. It’s kind of nice that there is now an accessible language for throwing together adventures. Thanks for getting the software up to date and the great tutorial.