Hiding in a container - or in other ways?

Hi folks,
I’m a bit of a novice coder but am trying to help some students at my Text Adventures club create their games. I was asked on Friday if Inform could do HIDING so that the prisoner could escape from the guards. So I said “Of course!”, not really thinking through how tricky this might be for me to code. Anyway, having magpied some code from one of Ryan Veeder’s games, I’ve been working on it most of the day and think that I’ve found something that seems to work. Does it actually work?

I scaled back my ambitions a bit to concentrate on hiding in just containers. I wasn’t sure how to replace the automatic descriptions for ‘On the desk’ etc for supporters. I also wasn’t sure how I’d implement ‘HIDE behind’…

Anyway, I’d be really grateful if anyone could look over / debug my existing code with whatever duct tape it needs. If there is a more elegant solution anyone knows of, happy to be pointed in the right direction.

PS I found the get in / get out of verbs a bit cranky in the Inform rulebooks so created a new one - am I missing something here?
PPS I enjoyed wrestling with this and think Inform is amazing for a non-programmer to use!

Chapter 0 - Scene setting 
		
A scene can be stealthy. 

Guard-attack is a stealthy scene. Guard-attack begins when the player is in the Corridor for the first time. Guard-attack ends when the guards are in the Cells for the first time.

When Guard-attack begins: 
	play Guard-chat;
	Guard-coming plays in two turns from now;
	Guard-corridor1 plays in three turns from now;
	Guard-corridor2 plays in four turns from now;	
	Guard-depart plays in five turns from now.	
		
To play Guard-chat:
	say "You hear a loud shout of 'Secure all the prisoners!' to the north."
	
At the time when Guard-coming plays:
	say "You can hear the sound of footsteps running towards you from the north."
	
At the time when Guard-corridor1 plays:
	now the guards are in the Corridor;
	say "The guards have arrived... [run paragraph on]";
	if hidden is true:
		say "Outside the bin, you can hear them scuffling and shuffling around the desk.";
	else:
		say "And they have found you [if player is not in the bin]standing in the middle of the corridor[else]sitting in the bin with the lid open[end if]!";
		end the story saying "You're back in prison!";
		
Every turn when the guards are in the location:
	if hidden is true: 
		continue the action;
	else:
		say "Oh no... Your activity has alerted the guards... And they have found you!";
	end the story saying "You're back in prison!"

At the time when Guard-corridor2 plays:
	say "You hear a muffled shout about heading to the cells and grunts of agreement from the other guards."

At the time when Guard-depart plays:
	now the guards are in the Cells;
	say "You hear the footsteps echoing southwards and then an eerie silence - sounds like the coast is clear."

Chapter 1 - Hiding 

Hidden is a truth state that varies.

To decide whether hidden is true:
	if attacking the big bin when the guards are in the location, decide no;
	if pushing the big bin when the guards are in the location, decide no;
	if jumping when the guards are in the location, decide no;
	if a closed container contains the player, decide yes;
	decide no.
	
Hiding in is an action applying to one thing.
Understand "hide in/inside/under/underneath/behind [something]" as hiding in. Understand "get under [something]" as hiding in. 

Getting out of is an action applying to one thing.
Understand "get out of [something]" as getting out of.
Before getting out of something:
	try exiting.
	
A thing can be a hiding-place. The big bin is a hiding-place.

Check hiding in:
	if the scene is not stealthy:
		say "There are no guards around, so no need right now." instead;
	else if the noun is not a hiding-place:
		say "[The noun] wouldn't make much of a hiding spot." instead;
	else:
		continue the action.
		
Instead of hiding in the big bin:
	say "You wriggle inside, close the lid after you so that you can't be seen and are plunged into...";
	now the big bin is closed;  
	now the player is in the big bin.
		
Instead of entering the big bin:
	try hiding in the big bin.
	
Before exiting:
	if the big bin is closed:
		silently try opening the big bin;
		continue the action.
	
Instead of entering the desk:
	try hiding in the desk.
	
Instead of hiding in the large desk:
	say "You try hiding under the desk. But your legs poke out so you stand up again.".
	

Chapter 2 - Place setting 

The Cells is room. North from the Cells is the Corridor. North from Corridor is the Armoury. The bed is enterable supporter in the Cells. The large desk is an enterable supporter in the Corridor. The big bin is a closed openable container in the Corridor. 

The guards are a plural-named person in Armoury. 

Check going north:
	if location is Corridor and the guards are in Armoury:
		say "But that's where the guards are right now!" instead.

Check going south:
	if location is Corridor and the guards are in Armoury:
		say "You freeze - there's no way you're going back in that cell!" instead;
	if location is Corridor and the guards are in Cells:
		say "But that's where the guards are right now!" instead.
1 Like

Your code looks good (any code that does what you want while not doing things you don’t want is already doing well!).

There are a couple of ways to take advantage of built-in concepts that might help.

Inform has a visibility relation with the associated verb to be able to see, so if a guard can see the player can act as an “if the player is not hidden” test.

I’m not sure what you found cranky about get in or out, but it seems like it’d be helpful to make use of some of the entering functionality…

hiding in is an action applying to one thing.
Understand "hide in/inside/under/underneath/behind [something]" as hiding in.
Understand "get under [something]" as hiding in.

before hiding in something when a stealthy scene is happening, instead try entering the noun. [ re-dispatch the action to entering]

instead of hiding in something when a stealthy scene is not happening, say "There's no need to hide." [ don't actually need "when a stealthy scene is not happening" because the before rule, above, ensures we don't get here otherwise ]

check entering a container when a stealthy scene is happening and (the noun is not openable or the noun is transparent): instead say "No good, they'd be able to spot you." [ can add more specific messages about legs sticking out, or whatever, as desired ]

Carry out entering a container when a stealthy scene is happening:
  now the noun is closed.

Last report entering a container when a stealthy scene is happening:
  say "You shut [the noun] after you."

A downside is that the message for entering the desk is “You get into the desk”. You might be interested in the Enterable Underside extension, which includes the Prepositional Correctness extension, which would allow making that “under the desk”.

3 Likes

A few pointers that may be of interest:

  1. There’s no need to declare hidden as a truth state in your code, since you’ve created a “phrase to decide” (To decide whether hidden is true) that doesn’t depend on a particular variable. When you say if hidden is true, the program won’t actually look at your variable, just execute the specified checks and decide true or false.

  2. The big bin is not specified as enterable but for consistency’s sake you may want it to be.

  3. Your rule Before exiting: will be run no matter the spatial context. This means, for example, that exiting the bed will result in the player trying to open the big bin, with a resulting message that You can't reach into the Corridor.

  4. Using an Instead rule to get things done is quite common but not without its potential drawbacks. I wouldn’t worry about it for now, but be ready to change as your comfort level with action processing grows.

  5. Your Check hiding in rule uses a condition if the scene is not stealthy which almost certainly doesn’t do what you think it does. It should probably be rephrased as if a stealthy scene is not happening. (EDIT: Oops, that’s still wrong – the condition I gave translates as “if at least one non-stealthy scene is not happening,” so if there were more than one stealthy scene it would cause a bug. See StJohLimbo’s item 1 below, which has the correct phrasing.)

2 Likes

(Zed’s proposal looks good; I typed these suggestions up separately in the meantime, maybe they’re helpful, too.)

You’re off to a good start, but there are some things I’d change:

1.

You have a condition “if the scene is not stealthy”:

Check hiding in:
	if the scene is not stealthy:
		say "There are no guards around, so no need right now." instead;

As a rule of thumb, using “the” in such conditions rarely leads to the results which the author intended. Inform mostly doesn’t know enough from the context to understand what “the <...>” is referring to. In practice, it is often treated as if you had written “a scene”.

And indeed, if the player tries to hide in something which is not a hiding place (for example if we add a matchbox in the Corridor), the game will say: “There are no guards around, so no need right now.”, even though the guard-attack scene is actually happening. I’m pretty sure that the reason is that another scene exists, namely the “Entire Game” (the default scene in Inform), and that scene is not stealthy.

Apart from the issue with “the”, the line doesn’t specify what other conditions the scene should fulfill, namely whether it is happening or not.

So, I’d replace the condition “if the scene is not stealthy” with: “if no stealthy scene is happening”.

2.

You don’t need “continue the action” at the end of a check rule; the action will automatically continue unless you prevent it by saying that Inform should do something else “[…] instead.”

3.

You’ve got “Check hiding in”, but then “Instead of hiding in the big bin”. Instead rules come before Check rules (memorizable abbreviation: BICCAR - Before Instead Check Carry-out After Report), so in the case of the bin, the Instead rule will override the Check rule and the player will be able to hide in the bin again, even when the guards are gone and there’s no need anymore. I’d turn the Instead rule into a Carry out rule.

2 Likes

Thanks so much for these tips!

@Zed
I’m just scratching the surface of how thoroughly Inform seems to track NPCs around the game world - it’s surprising (and for all the right reasons) unlike most of my code! Thanks for the super-clean solution.

@otistdog

  1. Gotcha, I think - useful tip.
  2. Oooops! Thanks for catching that one. Being specific is so important in coding, I’m finding.

@StJohnLimbo
1/2/3 Appreciate the explanation of scenes which really helped. I sense that they’re probably a touch above my paygrade at the mo but keen to give them a go… and BICCAR - that’s on the Post-it board already!

Cheers

1 Like