Dumb newbie question: Every turn alternative

I have scoured the documentation for Inform 7 and I cannot find the answer to this. It’s probably incredibly simple but I can’t work it out.

What I want to do is this: if the player goes into a room, and the player is carrying a parrot, the parrot should squawk. At the moment I am using this code…

Every turn:
	if the player carries Polly and the player is in the Sinister Inn:
		say "Polly squawks mournfully. She doesn't like it in here."

Now this is fine, it does what I intend, but because it checks for it on every turn, it does it repeatedly. What I would like it to do is present the phrase ONLY when the player goes into the room, beneath the room description, but I can’t work out how to do it. The nearest I’ve got is After going to the Sinister Inn, instead of Every turn which semi works, because it presents the phrase, BUT it prevents the room description coming up. And I can’t find an instruction to restore the room description.
Is there an alternative? Or am I going to have to write some stupidly excess code to count turns and prevent the parrot squawking after more than one?

You can say:

After going to the Sinister Inn when the player carries Polly:
    say "Polly squawks mournfully.  She doesn't like it in here.";
    continue the action.

However this will print it each time you go there, and it will print it before the room description, which may not be intended.

An every turn rule is the only way I know of to reliably get something to print after the full room description. There are ways to get Inform itself to keep track of how often you’ve done something (for the first time) but I don’t think they work in this particular context, so yes, you’ll probably need to use a variable or flag to keep track of whether this has already been printed.

1 Like

I’m on mobile and can’t test this at the moment, but something like this should work:

The Polly squawking rule is listed after the describe room gone into rule in the report going rules. 

This is the Polly squawking rule:
    if the player carries Polly and the location is the Sinister Inn:
        say "Polly squawks mournfully.  She doesn't like it in here.";
1 Like

What I usually do is:

EnteredInn is a number that varies. EnteredInn is 0.

Before going to the Sinister Inn when the player carries Polly:
    now EnteredInn is 1;

Every turn:
    if EnteredInn is 1:
        say "Polly squawks mournfully. She doesn't like it in here.";
        now EnteredInn is 0;

It’s gross, but it works (although I didn’t know you could use ‘going to [room]’ as an action so that’s interesting).

Edit: Reading deusirae’s earlier message, adding a state to the parrot is probably better than a 0/1 variable. Same general idea but cleaner.

1 Like

Arguably better than the 0/1 variable (and arguably worse than the property on the parrot), you can use a truth state that varies:

EnteredInn is initially false.

Before going to the Sinister Inn when the player carries Polly:
    now EnteredInn is true;

Every turn:
    if EnteredInn is true:
        say "Polly squawks mournfully. She doesn't like it in here.";
        now EnteredInn is false;

Another way (I think) is to use the condition if the Sinister Inn was not visited, which will check if the fact that the inn is not visited was true at the start of the turn. If the inn was not visited at the start of the turn but is now, that means we just entered it.

But it takes some time to get used to conditions in past tense, and it’s not always the best solution.

2 Likes

You could define a new property:

The Sinister Inn can be just-entered.

That reads a little nicer and you don’t need a past-tense condition. Plus you could extend it to any number of rooms, or even

A room can be just-entered.
3 Likes

Another possibility, if Polly will react to multiple rooms or have reactions to the second or third time visiting a room:

Every turn when going and the player carries Polly:
	repeat through the table of polly commentary:
		if the room entry is the location:
			say "[the comment entry][paragraph break]";
			blank out the whole row;
			make no decision.

Table of Polly Commentary
room	comment
Sinister Inn	"Polly squawks mournfully. She doesn't like it here."
1 Like

Wow, thanks guys - lots of different things to try, very helpful :slight_smile:

1 Like

I can confirm that this does indeed work perfectly :slight_smile:

2 Likes