Boilerplate for ScottKit games: standard actions

After the recent sequence of ScottKit tutorials (building gamesrooms and itemsactions, 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:

item rum "bottle of rum" called rum at cell

action drink rum when carried rum
	destroy rum
	print "OK. I feel funny."

action inventory when !exists rum
	print "I'm carrying ... uh ... you're my best mate, you are."

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.)

Here are some simple implementations of these:

action score: score
action inventory: inventory
action look: look
action save game: save_game

action quit game
	print "OK, goodbye."
	game_over
action quit:
	print "Did you mean to quit? If so, type QUIT GAME."

(Requiring the two-word command QUIT GAME will help to avoid the situation where a player accidentally quits while trying to QUIETEN BABY or QUICKEN TURTLE.)

Default actions

You also might want to provide a default implementation for verbs that will do something different under other circumstances. EXAMINE is a classic example:

# In the body of the game:
item sign "sign"

action examine sign when present sign
	print "It says: leave treasure here, then say SCORE"

item lamp "old-fashioned brass lamp"
	called "lamp"

action examine lamp when present lamp
	print "It is not lit."

# Then later, in the epilogue boilerplate:
action examine:
	print "I see nothing special."

(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.

start cave
treasury throne

occur when !flag 1
	print "Welcome to the Tutorial adventure."
	print "You must find a gold coin and store it."
	set_flag 1

room cave "cave mouth"
	exit east chamber

room throne "gorgeously decorated throne room"
	exit south chamber

item sign "sign"

action examine sign when present sign
	print "It says: leave treasure here, then say SCORE"

item lamp "old-fashioned brass lamp"
	called "lamp"

action examine lamp when present lamp
	print "It is not lit."

item lit_lamp "lit lamp"
	called "lamp" nowhere

item empty_lamp "empty lamp"
	called "lamp" nowhere

lightsource lit_lamp
lighttime 10

action light lamp when present lamp
	swap lamp lit_lamp
	print "OK, lamp is now lit and will burn for 10 turns."
	look

occur when flag 16
	clear_flag 16
	swap lit_lamp empty_lamp
	look
	comment "The engine sets flag 16 when the lamp runs out"

item station "lamp-refilling station" at cave

action refill lamp when here station and present empty_lamp
	destroy empty_lamp
	refill_lamp
	print "The lamp is now full and lit."

room chamber "square chamber"
	exit east dungeon
	exit north throne
	exit west cave

# Flag 15 is on when and only when it is dark
occur when at chamber and flag 15
	clear_dark
	look

item cross "Wooden cross"
	called "cross"

room dungeon "gloomy dungeon"
	exit west chamber
	exit north crypt

occur when at dungeon and !flag 15
	set_dark
	look

occur 25% when at dungeon
	print "I smell something rotting to the north."

item door "Locked door"

item key "Brass key"
	called "key"
	at crypt

item door2 "Open door leads south"
	nowhere

action open door when here door and !present key
	print "It's locked."

action open door when here door
	swap door door2
	print OK
	look

action go door when here door2
	goto cell
	look

room cell "dungeon cell"
	exit north dungeon

item coin "*Gold coin*"
	called "coin"

room crypt "damp, dismal crypt"
	exit south dungeon

item vampire "Vampire"

occur when here vampire and carried cross
	print "Vampire cowers away from the cross!"

occur when here vampire and !carried cross
	print "Vampire looks hungrily at me."

occur 25% when here vampire and !carried cross
	print "Vampire bites me!  I'm dead!"
	game_over
	comment "vampire can attack unless cross is carried"

action get key when here vampire and !carried cross
	print "I'm not going anywhere near that vampire!"

item rum "bottle of rum" called rum at cell

action drink rum when carried rum
	destroy rum
	print "OK. I feel funny."

action inventory when !exists rum
	print "I'm carrying ... uh ... you're my best mate, you are."

action score: score
action inventory: inventory
action look: look
action save game: save_game

action quit game
	print "OK, goodbye."
	game_over
action quit:
	print "Did you mean to quit? If so, type QUIT GAME."

action examine:
	print "I see nothing special."

verbgroup get take g
verbgroup drop leave
verbgroup examine x
noungroup lamp lantern

And here is how it plays:

$ 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.
$
Advertisements

2 responses to “Boilerplate for ScottKit games: standard actions

  1. 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.

  2. Thanks, Kaleberg! I’d love to see whatever game you make with it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s