Kindle IF Screensaver
Berlin Noir

Adding a Clues command


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] ";
            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].";
    if N is 1:
        say "There is 1 item left to find in the [location].";
        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.


Feed You can follow this conversation by subscribing to the comment feed for this post.

So...that seems pretty much like the way _LA Noire_ did it. You might want to have a toggle that turns it on or off for the more hardcore players, as that game did.

Thanks. LA Noire is much more sophisticated than what I'm doing. But that's a good suggestion on having a toggle. I'll have to figure out how to code that next!

Do you find that this is chewing up a lot of your memory? Lists seem to be enormous memory-hogs; I had a project with 62 lists and nothing else (one room, eight objects) and it blew right past the z-machine memory lists. But the only other way I can think of to implement this would be with a relation between rooms and objects, and that might also be very memory-hoggy. Anyway, since I assume you're in Glulx it probably doesn't matter!

I had to move to Glulx a while back, so memory hasn't really been an issue lately. I also created CLUES ON and CLUES OFF commands so you can disable this feature.

The comments to this entry are closed.