Print a different (look #room) the first time the room is visited?

In Inform 6, I got quite used to printing a different room description the first time a room is visited, to provide additional flavour text that is not essential to the game. This works because Inform 6 sets the visited flag only after printing the first look result.

The Dialog standard library seems like it sets the visited flag before trying to look, which also makes sense. Is there a better way to achieve what I want in Dialog?

Wait, I can use (select)Printed only once!(or)(stopping) of course!

3 Likes

I do think (select) is more idiomatic (and works as long as you don’t call the (look $) elsewhere), but it always bugged me that the visited flag was set before looking, because the documentation says that “the narration predicates are queried before the game world is modified”.

Granted, we could argue that (look $) is not a narration predicate, and that the visited flag is set after the player moving (but I haven’t checked) and it just happens that looking occurs after that, but still. I still find that checking the visited flag in the look is a useful pattern.

3 Likes

Yeah, the reason ($ is visited) gets updated before calling (look $) is because that flag is set in (update environment around player), the predicate that (among other things) checks for light and moves backdrops and floating objects into the room. So that always needs to happen before (look $) takes over, otherwise backdrops wouldn’t appear in the room description.

But, that could potentially be changed so ($ is visited) gets set in the rules for the LOOK action itself, after the call to (look $). That would have a few knock-on changes—if you LOOK inside a closed container, it would make the most sense implementation-wise for the ($ is visited) flag to get set on the container, not the room. But that doesn’t necessarily seem like a bad thing.

2 Likes

I think the currently visited room always being visited seems far more logical. And we still have an easy way to perform actions on the first look.

(A way which generalises to any action, I might add. The if (location hasnt visited) Inform 6 trick only works for the LOOK action.)

3 Likes

(look $) gets multiqueried so i tend to do something like:

(look *) 
     (entered *) 
     Standard description thereafter.
(look *)
     ~(entered *)
     (now) (entered *) 
      First wordy and special room description.

it’s no easier than using the (select $), it’s just more readable to my brain and seems more “dialog-like” to me.

i use this strategy a lot in (appearance $) queries for NPCs as well, although, i admit, (select $) would work fine in those cases also.

1 Like

Either way is fine; a select-statement in the form (select) (or) (stopping) (that is, exactly two options, stopping on the second one) is converted to exactly what you’re doing during compilation (setting and then testing a flag).

1 Like

That code would still work even if (look $) was a normal query, fwiw.