"after looking for the first time" triggers twice

I wanted to set up a bit of text to be shown after the initial room description at the beginning of the game (rather than before, as would happen if I used “When play begins”. However, in certain circumstances the text is showing twice.

This isn’t my actual code, but rather a tiny test case I put together to make sure it wasn’t some extension’s fault (it wasn’t):

[code]Example Room is a room. “It’s an amazing room!” A bed is here. Yourself is on the bed.

After looking for the first time: say “Oh my!”.[/code]

Here’s the transcript:

[code]Example Room (on the bed)
It’s an amazing room!

Oh my!

exit
You get off the bed.

Example Room
It’s an amazing room!

You can see a bed here.

Oh my!

[/code]

The correct transcript would be:

[code]Example Room (on the bed)
It’s an amazing room!

Oh my!

exit
You get off the bed.

Example Room
It’s an amazing room!

You can see a bed here.

[/code]

Does anyone know a way to fix this short of setting a truth-state variable? It only happens if the second look is triggered by exiting - if I do a regular look first and then exit, I only see the extra text once, as I should.

The best way to do this is avoid attaching it to looking and use one of Inform’s text-substitutions instead. (See ‘§5.7. Text with random alternatives’ in the docs for details of what I’m about to show you, and related handy tricks.)

Delete the line about ‘after looking’ and change the room description to this:

Example Room is a room. "It's an amazing room![first time][paragraph break]Oh my![only]".
That makes the stuff between ‘first time’ and ‘only’ only appear the first time.

This duplicates the transcript you asked for, where there’s a paragraph break between ‘room’ and ‘Oh my’. But you could have the Oh My on the same line, if you want, just by replacing the [paragraph break] with a space:

Example Room is a room. "It's an amazing room![first time] Oh my![only]".

-Wade

Well, it’s really not closely related to the room (which might be why I didn’t think of this solution)… but it’ll only ever be seen in that room after all, so I guess that solution is acceptable. Thanks.

It’s an interesting bug, I can’t quite tell what’s causing it. It has something to do with the turn count being the same during startup and the first turn.

If you want a rule-based solution, this works:

This is the oh my rule:
	say "Oh my!".
	
The oh my rule is listed last in the startup rules.

Oh, wait, the room description solution won’t work for my case, because there’s other things in the room.

[code]Example Room is a room. “It’s an amazing room!” A bed is here. A chair is here. Yourself is on the bed.

After looking for the first time: say “Oh my!”.[/code]

The transcript should be like this:

[code]Example Room (on the bed)
It’s an amazing room!

You can see a chair here.

Oh my!

exit
You get off the bed.

Example Room
It’s an amazing room!

You can see a bed and a chair here.

[/code]

However, Juhana’s solution does work correctly, so that’s great. (I made it a nameless rule instead though - “A last startup rule:”.)

You can still use “after looking” if you set your own flag.

Very-first-time is initially true.

After looking when very-first-time is true:
	now very-first-time is false;
	say "Stuff."

The looking action has a variable called “the room-describing action,” which stores the action that triggered the room description. When the game starts, that’s a normal looking action. When the player EXITS the bed, it’s a getting off action. So another way to get the behavior you want is:

After looking in the Example Room the first time: if the room-describing action is the looking action, say "Oh my!"