one time occurrence

So I’m doing what was suggested to me about figuring out the mechanics of specific things of the game before worrying about the entirety of it. I seem to have run into trouble with a certain mechanic involving the cause of a flood. If the player is wearing a certain thing, the player will survive. Otherwise, the player will die.

Here is the source I have:

[code]A vial is a container in Hills of Mantroche. Some water is in Hills of Mantroche. The indefinite article of the water is “some”.
The Lungs of Erdis is a proper-named thing in Hills of Mantroche. The Lungs of Erdis is wearable.

[YOU NEVER KILL WITHOUT WARNING! Change messages so that the player knows death is on its way if he/she doesn’t do something about it]

Last carry out going from Hills of Mantroche:
if the water is in the vial and the player carries the vial:
Erdis cries in five turns from now.

At the time when Erdis cries:
say “Erdis begins to cry.”;
the rain falls in two turns from now.
At the time when the rain falls:
say “Erdis’s tears rain from above.”;
the rain turns to torrent in two turns from now.
At the time when the rain turns to torrent:
say “The rain has turned into a heavy storm.”;
the lands flood in two turns from now.
At the time when the lands flood:
say “Erdis has flooded the land.”;
if the player is wearing the Lungs of Erdis:
say “Fortunately, since you wear the Lungs of Erdis, you manage to survive.”;
the skies clear in two turns from now;
else:
say “Water fills your lungs and you die.”;
end the story saying “You have drowned to death.”
At the time when the skies clear:
say “The skies have cleared and you’re good to go.”[/code]

So, this does what I want it to do, for the most part. After the player leaves the room “Hills of Mantroche”, it checks to see if the player is carrying a vial full of water. If the player is, then after five turns, the rain starts, then every two turns it increases into a larger and larger storm until it floods. But I have two issues with the way I’ve written this. For one, I’m positive there must be some more elegant way to write this as opposed to having one event linked to another. Also, as I’m sure you noticed, this whole thing will occur EVERY time the player leaves “Hills of Mantroche” (so long as he/she is carrying the vial of water), whereas I only want it to occur one time.

I am thinking using a scene is the answer to both my problems, but when I tried to do this, it got very messy very fast. I would post what I had for the source I had when I tried using a scene, but I forgot to save that version because I’m a genius like that.

Anyway, any ideas would be greatly appreciated. Thanks! :slight_smile:

Your way works, so it’s fine. You can easily solve the problem of repeats by setting a flag.

But yes, you could use a scene instead. I’d probably do something like this.

Erdis Cries is a scene. Erdis Cries begins when the water is in the vial and the vial is not enclosed by the Hills of Mantroche.
Erdis Cries ends when the Table of Flood Warnings is empty.

Every turn while Erdis Cries is happening:
	let T be the minutes part of the time since Erdis Cries began;
	if  there is a time elapsed of T in the Table of Flood Warnings:
		choose a row with time elapsed of T in the Table of Flood Warnings;
		say the message entry;
		blank out the whole row.

Table of Flood Warnings
Time elapsed	Message
2	 "Erdis begins to cry."
4	"Erdis's tears rain from above."
6	"The rain has turned into a heavy storm."
8 	"[Flood]"
10	"The skies have cleared and you're good to go."

To say Flood:
	say "Erdis has flooded the land.";
	if the player is wearing the Lungs of Erdis:
		say "Fortunately, since you wear the Lungs of Erdis, you manage to survive.";
	else:
		say "Water fills your lungs and you die.";
		end the story saying "You have drowned to death."

Thanks, jrb. I am completely unfamiliar with flags, and I’m intimidated by the use of tables, so I’m looking forward to trying it your way so I can familiarize myself a little better. What exactly is the flag? Is that T? Also, the way I currently understand your source text, it seems like any time the conditions are met (water in the vial and vial not enclosed by Hills of Mantroche), the scene will start over again. Or am I mistaken? Will the scene only happen once? I seem to remember reading something in the documentation on recurring scenes. Or recurring scenes the only type of scene that will repeat themselves?

If you wanted to use a flag, you could create a variable, like this:

Flood-happened is a truth state that varies. Flood-happened is false.

And then somewhere in the flooding sequence, you’d add “Now flood-happened is true”:

At the time when the lands flood: say "Erdis has flooded the land."; if the player is wearing the Lungs of Erdis: say "Fortunately, since you wear the Lungs of Erdis, you manage to survive."; the skies clear in two turns from now; else: say "Water fills your lungs and you die."; end the story saying "You have drowned to death."; now flood-happened is true.

And then in this block of code that triggers the flood, you’d add a condition about flood-happened being false:

Last carry out going from Hills of Mantroche: if the water is in the vial and the player carries the vial and flood-happened is false: Erdis cries in five turns from now.

Another way you could do this, instead of the above, would be to add a new either-or property (like “already-flooded”) to an object in the game, like the vial:

The vial can be already-flooded.

Then, in the appropriate places in your code, you would be able to put things like “now the vial is already-flooded” and “if the vial is not already-flooded.”

If I’m reading jrb’s code correctly, no flag is needed. [Edited to remove incorrect explanation for this–see what jrb says below. I forgot scenes only happen once by default.]

By default scenes only occur once. If you want a scene to be repeatable, you have to declare it as a “recurring scene”.

I only blanked my table rows to give a suitable condition to test for the end of the scene. I could have done it in lots of other ways. Indeed, just writing

Erdis Cries ends when the time since Erdis Cries began is 11 minutes.

would do the trick, with no need for blanking rows. I guess the advantage of my slightly less direct way is that you can fine-tune the timing just by adjusting the data in the table – no need to scan your code for other parameters that might need changing.