Unavailable variables, or "There must be a better name for this topic"

Here’s an abstraction of the game I’m working on:

"Towel" by Philip Riley

The lab is a room. The monster's den is east of the lab.

Definition: a room is dangerous if the ravenous bugblatter beast of traal is in it.
Definition: a room is safe if it is not dangerous.

The ravenous bugblatter beast of traal is an animal. It is in the monster's den.

The towel is a wearable thing. The player is carrying the towel;

Before going from a safe room to a dangerous room:
	if the towel is touchable:
		try wearing the towel;
	if the player does not wear the towel:
		say "You can't go in there without a towel!";
		stop the action;

Check wearing the towel when the location is safe:
[Check wearing the towel when the location is safe and the room gone to is safe:]
	say "There's no point in wearing the towel in a safe place like this!";
	stop the action;

Running the code as is yields:

lab

> e

There’s no point in wearing the towel in a safe place like this!

You can’t go in there without a towel!

But reversing which line is commented yields:

> wear towel

Variable unavailable for this action, activity or rulebook: internal ID number 20007/1

You put on the towel.

Neither of these is unexpected. My question is how to get around it, while retaining the functionality. I could change the before to an after, but in the particular case in my game, it’s not acceptable to put on the towel after you’ve already seen the ravenous bugblatter beast of traal. Is there a way to check if a variable is available or not? By looking at MStack.i6t I can kind of see a way to check if a variable is available, but I really feel I’m way off track here.

The key is that “the room gone to” is a part of the going action. If the current action is not going, it doesn’t exist. This means it can’t be referenced in rules for any other action.

Since the wearing action can never succeed unless called by the before going rule, why use the action at all? Just call a phrase that makes the towel be worn.

Sure. Like I said, everything here is expected.

I could, although that loses any other rules I might apply, like:

Check wearing the towel when the day is Tuesday:
    say "On a Tuesday? Are you crazy?" instead;

I just hate the idea of enforcing all the rules that Inform is supposed to enforce for us, so I was looking for other ideas of how to obtain the same functionality without my erroneous rule.

I just tweaked your code a little here:

EDIT: changed some wonky behavior, but in this example you can still take off the towel in a dangerous room and then, if you leave, you can’t go back to get it. :slight_smile:

3 Likes

This is great, thanks for getting me past my block.

1 Like