Countdown timers and checks

I am having a slight issue with this code. AM I missing something?
ANY help is GREAT!
Thanks Wizards!

LC1 is a number that varies.  LC1 is 5.

Every turn when LC1 > 0:
		now LC1 is LC1 - 1.
	If lc1 >0:
		say "'Finally thew line moves!'";
		now the player is in newroom;
	otherwise:
		 say "Oh no, the line just is not moving.";

Your indentation is broken and inconsistent. And you have a period at the end of now LC1 is LC1 - 1., which terminates the rule, so the rest isn’t valid. You’ve also messed up the condition so that it happens immediately instead of waiting until the end.

This fixes all those issues:

LC1 is a number that varies.  LC1 is 5.

Every turn when LC1 > 0:
	now LC1 is LC1 - 1;
	If lc1 is 0:
		say "'Finally the line moves!'";
		now the player is in newroom;
	otherwise:
		say "Oh no, the line just is not moving.";

Although note that you can just decrement LC1 rather than explicitly subtracting 1 from it.

And finally, you can replace most of this using Inform’s built-in timer phrases:

When play begins:
	the line moves in 4 turns from now.
	
At the time when the line moves:
	say "'Finally the line moves!'";
	now the player is in newroom.

By default, Inform doesn’t have a way to make a rule that happens while the timer is pending (to print your the line is just not moving text), but you can use another condition for that, such as the player being in the room with the line. Alternatively, you can use an extension that extends the capabilities of reporting on timed events, such as Phrases for Adaptive Pacing by Ron Newcomb.

You really need to read that Problem Report; it did tell you most of this. Searching the documentation for things related to what you’re trying to do can also be helpful.

2 Likes

It’s a little hard for me to make out what’s meant to be happening here, but I think you have a syntax issue as well as a logic issue. The syntax issue is that you have a period after the second line of your Every Turn rule, but you should only put a period at the end of the rule (you also don’t have a period at the very end of the rule). The logic issue is that the If statement comes in the middle, when it should be at the end.

If what you’re trying to do is decrement LC1 until you hit 0, at which point the player is moved to newroom, this might work (though note that you’d probably want to do some refinement, like only counting down LC1 while the player is in the room where the line is, and potentially suspending or resetting the timer if the player leaves during the countdown):

Every turn when LC1 is greater than 0:
	If LC1 is greater than 0:
        say "Oh no, the line just is not moving.";
		decrement lc1;
	If LC1 is 0:
		say "'Finally the line moves!'";
		now the player is in newroom.

That’s not actually required, provided that you leave a blank line between different rules. Some people might find it easier to remember just using a semicolon always and never a period. That can sometimes make it easier to rearrange the order of things in the rule as well.

Note though that there’s still some issues with your version of the rule. The first if is entirely redundant; it will always be true if the rule is running at all, since the condition is the same as the opening clause. Also, on the turn when LC1 does reach zero it will print both bits of text.

3 Likes

Oh, interesting, didn’t know that about rules – thanks for pointing that out (and the crufty bits in my example)!

Both suggestions worked. Thanks to all.