If to display

I can use if /else statements in a description no problem at all. All I want to be able do is print on the screen a simple message after a condition. Ive tried things from the forum chats, Ive been looking on the net but still no joy. Ive tried say "[ if padlock is locked and location is bedroom]You are locked to a bed by a chain and cant move.".
also
if padlock is locked say “You are locked to a bed by a chain and can`t move.”.

and loads of other combinations. I`m enjoying getting to know inform 7 and starting to write an adventure game again but this is driving me crackers. Cheers.

Can you post an example of source code that isn’t working for you using the preformatted text option so line breaks and stuff come through (it’s the button that looks like “</>”)? The syntax you’re posting looks like it should work, so there might be whitespace issues or something else going on.

Edit: oh wait, I see what’s going on, I think. You can’t just put an if statement in your code and have it do anything - it needs to be part of a rule, so that Inform knows when to evaluate it. From context, it seems like you might want that text to display when the player tries to move (in which case you could write an instead of going rule) or any turn when they’re attached to the bed (in which case you could write an every turn rule). Or perhaps both or neither!

2 Likes
Every turn when padlock is locked:
	say "You are locked to a bed by a chain and can`t move far.";

Ive tried the above to hopefully run a check every turn but it does not print out the result. Any idea with this the chain and padlock are visible in the room but I dont want the padlock to be seen until the player examines the chain.

This looks to me like it should work, so are you sure the padlock exists and is locked? You can type SHOWME PADLOCK when testing to check.

1 Like

Before the every turn lines I have.

The padlock is a container. The padlock is locked. The description is "A solid padlock with a small key hole."
The padlock is in the bedroom.

That shows the padlock in the room, so I put the padlock is nowhere so I can make it appear when the chain is examined and it does not come on the screen.
But I can`t get the “chained to bed to appear”

If you put the padlock nowhere, then it isn’t checked in the “every turn” rule. Why would it be? It isn’t anywhere, and shouldn’t be relevant.

Instead of removing the padlock from play, you could make it scenery to prevent it from showing up in the room description:

Bedroom is a room.

The padlock is here. It is scenery. The padlock can be locked or unlocked. [This seems less hacky than making it a container to me.] It is locked. The description is "A solid padlock with a small key hole."

Every turn when padlock is locked:
	say "You are locked to a bed by a chain and can't move far.".

This works for me.

But note that this code, like yours, doesn’t prevent you from moving, it just displays the message in addition to whatever action you take during that turn. I assume you have other code to cover that.

1 Like

This code works for me too, but that first part isn’t quite right – it works if the padlock is nowhere/out of play, as well. So @Baldielocks, it sounds like you might have something else odd going on with how you’ve set up the padlock that’s causing the issue. Can you post a code excerpt that reproduces the behavior?

I copied your code and organized it a bit:

bedroom is a room.

The padlock is in the bedroom.
The padlock is a container.
The padlock is locked.
The description is "A solid padlock with a small key hole."


Every turn when padlock is locked and the chain is examined:
	say "You are locked to a bed by a chain and can't move far.";

output:

Welcome
An Interactive Fiction
Release 1 / Serial number 250402 / Inform 7 v10.1.2 / D

bedroom
You can see a padlock (closed) here.

>z
Time passes.

You are locked to a bed by a chain and can’t move far.

So far as mentioning or not mentioning the padlock, depending on whether or not the chain has been examined, there are a few options. Perhaps the padlock is attached to the chain:

the padlock is part of the steel chain

You can conceal it until the player examines it:

rule for deciding the concealed possessions of the steel chain:
	if we have examined the steel chain:
		decide no;
	otherwise:
		decide yes.

In this case, the padlock is a “possession” of the steel chain because it is part of it. The posessions of the chain are concealed until the player examines the chain. This can be tied into your every turn rule:

Every turn when padlock is locked and the padlock is not concealed:
	say "You are locked to a bed by a chain and can't move far.";

output:

>z
Time passes.

>z
Time passes.

>x chain
You see nothing special about the steel chain.

You are locked to a bed by a chain and can’t move far.

>z
Time passes.

You are locked to a bed by a chain and can’t move far.

Another option is just moving it:

After examining the steel chain:
	now the padlock is in the bedroom;

(You could make it scenery, or make it part of scenery, but I’m assuming you don’t want players to interact with it before it’s discovered)

3 Likes

Thanks for all the help guys it works now just as it should and yes Tobias I will want to prevent moving or getting to a wardrobe but interact with a bedside cabinet I don’t know how to do it yet butt I’ll give it a shot. Cheers.