Displaying figures when looking

I can display a figure everytime I get to a room using this code

"Learning IF" by "Me"

Figure of _coast is the file "Coast.png".
Figure of _sanddunes is the file "Sanddunes.png".

Coast is a room. "It is cool."
Before looking:
	display the figure of _coast

Now, how can I display the figure “only” once and display it again “only” if the player types look?
What happens now is everytime I enter the room it displays the figure again. I don’t want that.

You can try something like:

Before looking when the room-describing action is the looking action:

as the preamble for your rule. This feature of the Standard Rules is mentioned briefly in Recipe Book 6.9 Going, Pushing Things in Directions but is not mentioned in Writing With Inform.

3 Likes

I ran into a couple of problems with your example. Here is my update code

"Learning IF" by Me

Figure of _coast is the file "frasierx1.png".
Figure of _sanddunes is the file "sunmaid.png".

Coast is a room. "It is cool".
Instead of looking when the room-describing action is the looking action:
	Display the figure of _coast
	
Desert is a room. It is east of Coast."It is warm".
Instead of looking when the room-describing action is the looking action:
	Display the figure of _sanddunes

So what happens is this. When I hit play, the first image shows up automatically. Then, when I type look, the image shows up correctly. when going east after that, no image shows up but then when I type look the first image shows up instead of the correct image. I assume the rule is fixed after the first room? I just don’t know. Maybe you can clear that up.

I also tried “Before” and “After” … looking

Rules are not bound to specific locations unless something about the rule preamble (i.e. condition) involves that location. Instead rules and Before rules each have their own purpose, and they are distinct. See WWI 12.2 How actions are processed for an overview of the purpose of each built-in action processing rulebook.

Since the two rules have the same preamble, they are triggered under the same conditions (i.e. any time a looking action is generated by player command). Since they are Instead rules (which have default failure result), only one will actually fire before the rulebook processing ends. See WWI 19 Rulebooks for more on all this.

There is some hidden complexity in that that way the built-in code works, a looking action is (sort of) generated whenever entering a room. The room-describing action, a global variable provided by the built-in Standard Rules, makes it possible to decide whether the looking action is happening due to a change in location or due to the player typing >LOOK.

There is also a visited property of rooms that seems like it might be useful for your purpose, because you always want the figure to be shown on the first entry to a room.

Since it looks like you have a number of figures and an association between rooms and figures, it is helpful to establish a link between them. This can be done by setting up a figure-based property for each room, or, if not every room will have a figure, by using a relation between rooms and figures. That will make it possible to set up a single generic rule to handle all cases instead of trying to do it on a room-by-room basis.