Incrementing

For some reason, this code:

The player carries a look-counter.  The description of the look-counter is "[incremented looking]".

Looks is a number that varies.  Looks is one.

To say incremented looking:
	if looks is less than ten:
		say "You've looked at the counter [looks in words] time[s]!";
	else:
		say "Aren't you bored of this?";
	increment looks.

gives me this output (counting up by two instead of one):

If I use “increase looks by one” instead of “increment looks,” it still happens; if I instead “increase looks by zero” the expected lack of incrementing occurs. Does the “to say” phrase get called twice, or something?

I’m guessing the description is being printed to an internal buffer in the course of the examining action, then printed again to the screen. (The same thing happens with printed names, because Inform needs to see whether the first letter will be a vowel to print the indefinite article.)

EDIT: Aha. Inform prints it to a buffer to see whether it will turn out blank, in which case “You see nothing unexpected.” will be shown instead.

…oh. So I should basically never change any global variables in a “to say” phrase? I thought that was the whole point of “to say” phrases! :stuck_out_tongue:

More seriously, good to have that figured out. I’m running a little workshop tonight and thought that would be some innocuous code. I’ll use this instead:

[code]A Heisenberg Pixie is an animal here. The description of the Heisenberg Pixie is “[pixie displacement]”.

To say pixie displacement:
if the number of rooms is greater than two:
let R be a random room;
while R is the location:
let R be a random room;
now the Heisenberg Pixie is in R;
say “It’s gone in a blink – you have a suspicion that it’s now in [R].”;
else:
say “You get the distinct feeling it would rather be somewhere else.”
[/code]

If you move the text-with-incremental-substitutions from the description to an “instead of examining” phrase it will work.

You can also wrap variable-setting code in a [one of] construction, which doesn’t print anything during string comparison.

Yeah, that’s what I would do if I didn’t specifically want an example of a “to say” phrase. I might strike this example anyway (especially since it’s likely that participants will run into this same problem), but I like the idea of peeking a little at the diversity of ways to accomplish stuff in Inform.

I think the moral is not to change global variables in a description – changing them in a “to say” should be OK if you don’t call that phrase from a description.

Right. The description and printed name properties get “preflighted” (for different reasons). Other printed text is printed exactly once.

It’s also safe to make changes if they’re safe to repeat, obviously. I sometimes use a phrase

To say ever-seen (T - thing): now T is ever-seen.

Then I can stick “[ever-seen obj]” into a description. It doesn’t matter that it gets called twice.

You could use “regarding” as an example of a say-phrase which often comes up in descriptions.

Uh! Just Yesterday I tried this code (having to show the image of an object):

[code] A cat is an animal. The description is “[show figure of cat]It[’]s just ONE cat.”

To show (FIG - a figure name): display FIG.[/code]

The result was an image displayed twice. I’ve lost some time to find the bug without any success. Now I understand what’s going wrong. Thank you!