Starting a turn timer

I’m trying to set up a scenario as follows:

The player is wandering freely through a collection of rooms. As soon as the player enters the last room, they only have a maximum of 8 moves left until an ending occurs. They can carry out an action in less than 8 moves that will result in a desired ending, or if the 8 turns expire the player dies.

I’m a very new Inform user, and the only reason that I’m trying something this ambitious is that I’m in a college game design class and this is the key mechanic of my final game. I’m completely lost. I don’t know if I need to create a system for keeping track of turns or if Inform can do that itself. I also don’t know any of the syntax for checking conditions.
I would really appreciate an explanation of how Inform processes the idea of turns/actions and how to program what I described.

Thanks!

(With apologies to Jack Vance)

[code]The ruined hall is a room. “He had a clear view of the room. Bare and barren.”

There is a tapestry in the ruined hall. “Bare, barren, except for the bit of golden tapestry.”

Instead of taking the tapestry:
say “He stepped forward and swiftly jerked the tapestry down from the wall.[paragraph break]And behind was Chun the Unavoidable.”;
the inevitable occurs in eight turns from now.

At the time when the inevitable occurs:
end the story saying “At his elbow a voice said, ‘I am Chun the Unavoidable.’”[/code]

Note that, in this version, nothing can stop the inevitable from occurring once it’s been scheduled. If the game continues for eight more turns, Chun will find the player, no matter what.

This is perfectly fine if their goal is to win or otherwise end the game before that happens. But if you want to let the player stop the inevitable somehow, you can use my extension Cleared Events. With the extension you can say “the inevitable occurs never” to stop the timer.

Fantastic, that’s exactly what I need!

In addition to having an event occur after eight turns, I need a different message to print after the player takes each of those turns. The messages need to appear in the same order every play-through so I can’t select randomly from a table.
How do I tell Inform to print a certain message after the player takes a turn? Can I do something like:

Every turn: if the inevitable occurs in eight turns: say "Woohoo! Eight turns until you die!" if the inevitable occurs in seven turns: say "Better hurry up! Your death is approaching!"

And so on?

I don’t think there’s a way to check if an event is scheduled. One thing you can do is set a flag that says that the trigger has been set, and then key a say phrase to that:

[code]The ruined hall is a room. “He had a clear view of the room. Bare and barren.”

There is a tapestry in the ruined hall. “Bare, barren, except for the bit of golden tapestry.”

Chun awakened is a truth state that varies.

Instead of taking the tapestry for the first time:
say “He stepped forward and swiftly jerked the tapestry down from the wall.[paragraph break]And behind was Chun the Unavoidable.”;
now Chun awakened is true;
the inevitable occurs in eight turns from now.

Every turn when Chun awakened is true: say “[one of]He turned on paralyzed legs and they were leaden, like legs in a dream which refused to run.[or]He dropped out of the wall and advanced. Over his shiny black back he wore a robe of eyeballs threaded on silk.[or]He sprang, he soared. The tips of his toes scarcely touched the ground. And behind came Chun, running like a dog.[or]He sped along the crest of a wall and sprang a great gap to a shattered fountain. Behind came Chun.[or]He darted up a narrow alley, climbed over a pile of refuse, over a roof, down into a court. Behind came Chun.[or]He sped down a wide avenue lined with a few stunted old cypress trees, and he heard Chun close at his heels.[or]He felt a stir behind him, a breath of air.[or][stopping]”.

At the time when the inevitable occurs:
end the story saying “At his elbow a voice said, ‘I am Chun the Unavoidable.’”[/code]

Althooough it might be better not to have two separate mechanisms, one to print the messages and one to cause the player’s doom. If you try my program you’ll notice that I run out of messages before Chun shows up.

Another way to handle the whole thing might be to make a variable that’s a countdown timer:

[code]The ruined hall is a room. “He had a clear view of the room. Bare and barren.”

There is a tapestry in the ruined hall. “Bare, barren, except for the bit of golden tapestry.”

Turns since Chun awakened is a number that varies.

Instead of taking the tapestry for the first time:
say “He stepped forward and swiftly jerked the tapestry down from the wall.[paragraph break]And behind was Chun the Unavoidable.”;
now turns since Chun awakened is 1.

Every turn when turns since Chun awakened is greater than 0:
if turns since Chun awakened is:
– 1:
say “He turned on paralyzed legs and they were leaden, like legs in a dream which refused to run.”;
– 2:
say “Chun dropped out of the wall and advanced. Over his shiny black back he wore a robe of eyeballs threaded on silk.”;
– 3:
say “He sprang, he soared. The tips of his toes scarcely touched the ground. And behind came Chun, running like a dog.”;
– 4:
say “He sped along the crest of a wall and sprang a great gap to a shattered fountain. Behind came Chun.”;
– 5:
say “He darted up a narrow alley, climbed over a pile of refuse, over a roof, down into a court. Behind came Chun.”;
– 6:
say “He sped down a wide avenue lined with a few stunted old cypress trees, and he heard Chun close at his heels.”;
– 7:
say “He felt a stir behind him, a breath of air.”;
– 8:
end the story saying “At his elbow a voice said, ‘I am Chun the Unavoidable.’”;
increment turns since Chun awakened.
[/code]

(Check out §11.8 of the documentation to see how the – syntax works. And, if it makes you feel better as a newcomer, I had to try about five times before I got all the correct punctuation.)

The advantage of this is that it keeps all the code in one place so you can be sure that the turns till doom doesn’t get out of sync with the messages.

Another thing to watch out for you if you use the timed events is to make sure that you don’t accidentally reset the timer. In Draconis’s code you can avoid Chun by taking the tapestry again–this triggers “The inevitable happens eight turns from now” once more, which reschedules the event for eight turns in the future.

It’s possible to extract the number of turns remaining from a scheduled event if you really want to, using a bit of I6. But Matt’s solution is cleaner. If you make your own counter you have complete control over it.

Here’s my very simple and clunky method to do this.

[code]Lab is a room.

To say explosion:
say “KABOOM. The bomb has exploded. You aren’t aware of this, however, as humans work most efficiently in one piece.”;
end the story.

Disabled is a truth state that varies.

Every turn when disabled is false:
say “[one of]A tinny voice says ‘Countdown initiated.’ You wonder who said that.[or]‘Five…’[or]‘Four…’[or]‘Three…’[or]‘Two…’[or]‘One…’[or]‘It’s been nice knowing you…’[or][explosion][stopping]”

Instead of doing anything to the bomb when disabled is false:
say “Never mind that! You use your superior technological skills to defuse the bomb. Whew. Crisis averted.”;
now disabled is true;
credits roll in three turns from now;

At the time when credits roll:
end the story saying “You saved the space station and all its inhabitants! What a happy ending!”

A bomb is in lab. The description is “It’s a neutralized bomb. Good work.”[/code]

Matt w’s solution could be made into a scene, saving a little work with the time counter.

The Place of Whispers is a room. "He had a clear view of the room. Bare and barren."
There is a tapestry in the Place. "Bare, barren, except for the bit of golden tapestry."
After taking the tapestry for the first time:
	say "He stepped forward and swiftly jerked the tapestry down from the wall.[paragraph break]And behind was Chun the Unavoidable.";

Fleeing the inevitable is a scene. Fleeing the inevitable begins when we have taken the tapestry.
Every turn during fleeing the inevitable: 
	if the minutes part of the time since fleeing the inevitable began is:
		-- 1: 
			say "Liane screamed. He turned on paralyzed legs and they were leaden, like legs in a dream which refused to run.";
		-- 2: 
			say "Chun dropped out of the wall and advanced. Over his shiny black back he wore a robe of eyeballs threaded on silk.";
		-- 3: 
			say "Liane was running, fleetly now. He sprang, he soared. The tips of his toes scarcely touched the ground. And behind came Chun, running like a dog.";
		-- 4: 
			say "Liane sped along the crest of a wall and sprang a great gap to a shattered fountain. Behind came Chun.";
		-- 5: 
			say "Liane darted up a narrow alley, climbed over a pile of refuse, over a roof, down into a court. Behind came Chun.";
		-- 6: 
			say "Liane sped down a wide avenue lined with a few stunted old cypress trees, and he heard Chun close at his heels.";
		-- 7: 
			say "He felt a stir behind him, a breath of air.";
		-- 8: 
			end the story saying "At his elbow a voice said, 'I am Chun the Unavoidable.'";