Printing turn count

I want to print turn counts 0, 1, 2… My two code approaches prints the first number twice instead. What’s the drawback to this? What am I not being aware of? Thanks in advance… :wink:

First code snippet

"Test Turns" by mim

The Test Room is a room. "[turn_count]"

To say turn_count:
	say "[turn count]".

The result is:

Test Turns
An Interactive Fiction by mim
Release 1 / Serial number 200128 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

Test Room
1

>l
Test Room
1

>l
Test Room
2

>

Second code snippet:

"Test Turns" by mim

Turn_count is a number that varies. Turn_count is 0.

Every turn:
	increment turn_count;

The Test Room is a room. "[turn_count]"

The results is

Test Turns
An Interactive Fiction by mim
Release 1 / Serial number 200128 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

Test Room
0

>l
Test Room
0

>l
Test Room
1

>l
Test Room
2

>

This happens because the turn is not over yet when the action is being done, so ‘looking’ will merely repeat the value the turn count as it was at the end of the previous turn. The turn count increases by 1 at the very end of the turn–ie when ‘looking’ is done, and all is described. The first turn in any game is always taken by the initial ‘look’ in the initial location(before the PC does anything, even ‘looking’. So your first snippet is going to show a 1 in both the initial location description, and in the ‘looking’ action (because the room description prompted by the ‘looking’ is printed before the turn count actually increases by 1). So naturally, the second ‘looking’ is going generate a 2–when at the end of that turn, the turn count is actually 3(!).

For your second snippet, it’s really the same story–only you begin ‘turn_count’ with a value of 0 (when the actual turn count is going to be a 1)–the Every turn rule fires only at the end of the turn(or somewhere near it), so the room description prints before it can fire thus you get a value that is 1 less than the actual turn count.

One easy fix, if your goal is to have it print the actual turn count (for the end of that turn)–instead of using [turn count] use [turn count plus 1].

1 Like

Doing it the above way, you still get the repeat, only starting with “2.” If that’s what you’re trying to get rid of (and you want “0” the first time) try:

The Test Room is a room. "[one of]0[or][turn count][stopping]"
1 Like

The other half of the reason – this might not be clear from the above explanations – is that there is no “every turn” phase between the initial “when play begins” (when the room description is initially printed) and the player’s first turn. Nor is turn count incremented.

You could do this:

The last startup rule (this is the initial tick rule):
	follow the every turn stage rule;
	follow the timed events rule;
	follow the advance time rule;

But you might need to adjust your every turn rules to account for the fact that they run before the first turn!

3 Likes

Thanks for clearing that up for me, Zarf.

1 Like

Thanks for your answers!

Problem is that I wanted to capture the value of the variable. Inspired by @BadParser I concocted the following code (it works!):

The zeroth_turn_flag is a number that varies. The zeroth_turn_flag is initially 1.

The turn_count is a number that varies.

The Test Room is a room. "[perform_trick][turn_count]"

To say perform_trick:
	if zeroth_turn_flag is 1:
		now the turn_count is 0;
		now zeroth_turn_flag is 0;
	otherwise:
		now the turn_count is the turn count;

Result:

Test Turns
An Interactive Fiction by mim
Release 1 / Serial number 200129 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

Test Room
0

>l
Test Room
1

>l
Test Room
2

>

Thanks again!

I had to rewrite the code to accurately reflect my intentions. The final version is:

"Test Turns" by mim

The turn_count is a number that varies. The turn_count is initially 1.

After looking when the player is in the Test Room for the first time:
	increment turn_count;
	
Every turn:
	increment turn_count;
	
Test Room is a room. "[turn_count]"

Result:

Test Turns
An Interactive Fiction by mim
Release 1 / Serial number 200129 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

Test Room
1

>l
Test Room
2

>l
Test Room
3

Thank you all for your help!

Edit: added the very important condition "when the player is in the Test Room "