Adding a Clues command
12/02/2011
Most of my effort on The Z-Machine Matter has been spent on cleaning up the writing and incorporating feedback from IntroComp. But last weekend, I had an idea and decided to implement a new feature. Since part of the game involves finding clues, I thought it might be worthwhile to have a command CLUES that tells the player how many items there are still to find in the current location. For newbie players, this would enable them to get some idea on where to focus their efforts without resorting to the full built-in HELP system. I also implemented a change to the status line so that the current location includes a * to indicate that there are items to find.
While not a particularly complicated piece of code, as with most of my work with Inform7, it took several failed attempts to figure out a way to implement this. I'm sure it's not the prettiest code, but it works.
For each room, I create a list called discoveries that includes all of the interesting objects that are hidden in that room. It might be something on a book case, in a locked drawer etc.
[ Each room has its own potential discoveries. ]
A room has a list of things called discoveries.
[ Set up interesting clues for each room ]
When play begins:
now the left hand status line is "Hotel Room *";
now discoveries of Hotel Room is {gun, bible, postcard};
now discoveries of Hotel Bathroom is {matchbook}.
Then whenever an object is examined or taken, I check if it's in the discoveries list and remove it.
Carry out examining something (called the item):
now the item is found;
if item is listed in discoveries of location:
remove item from discoveries of location.
[ Taking something also makes it found ]
Carry out taking something (called the item):
now the item is found;
if item is listed in discoveries of location:
remove item from discoveries of location.
And then every turn, I check if there's a need to update the * on the status line.
[ Check the status line after every turn. Show a * if there are undiscovered items. Avoid flicker if nothing has changed. ]
Every turn:
if discoveries of location is empty:
if last status location is not "[the player's surroundings] ":
now the left hand status line is "[the player's surroundings] ";
else:
if last status location is not "[the player's surroundings] *":
now the left hand status line is "[the player's surroundings] *".
And finally, here's the code for the Clues command.
Understand "clues" or "clue" as asking for clues.
Asking for clues is an action out of world.
Carry out asking for clues:
let L be discoveries of location;
let N be the number of entries in L;
if L is empty:
say "You've found all the items in the [location].";
else:
if N is 1:
say "There is 1 item left to find in the [location].";
else:
say "There are [N] items left to find in the [location].";
I've also posted a short Inform7 project you can download if you want to try it out yourself. It's a plain text file, so it might be easiest to cut & paste this into the Inform7 IDE.