A random action that won't repeat?

Let’s say I have a switch that causes something random to happen when pulled, but that action would only happen once, and once only. Essentially, it’s removed from the list of possible actions to happen after it’s triggered.

What’s a good, clean way to do that?

It’s an exception. That sounds like a good reason to use an Instead rule.

[code]The Cavern is a room. “A cavernous cavern.”

Some rocks are a thing. “Huge rocks lie here.”

The suspicious lever is a thing. The initial appearance is “A suspicious-looking lever protrudes from the wall.” It is fixed in place in the cavern. Instead of trying pulling the lever for the first time, have the player trigger a cave-in. Instead of pulling the lever, say “The lever is stuck.”

To have the player trigger a cave-in:
say “You pull the lever. With an ominous rrrrumble, rocks begin to fall, and you leap aside just in time.”;
now the rocks are fixed in place in the cavern.[/code]

As for whether that constitutes a good or clean way of doing it, I’ll defer to more experienced authors. The above works and is, I think, reasonably succinct.

No, emphasis on the word ‘random’. Maybe pulling the lever would cause a cave in, maybe it’d turn off the lights, maybe a whale would materialise out of thin air.

BUT, the same action couldn’t repeat. So only one cave in could be caused, only one whale would be summoned, you get the idea.

Hm, I read this a little differently than Eleas. I was thinking you were looking for a lever that when pulled, triggered a random event from a list of possibilities and then if pulled again, would trigger a different random event. This would continue until all the possible events were triggered (only one time each) and then some sort of default would be triggered.

This scenario made me think of text substitutions, which can execute code in addition to (or instead of) printing text. There are also a variety of different ways to randomize them using the “[one of]” tag (see ch 5.7). Anyway, this is what I came up with:[code]Lab is a room. The lever and a magic ball are in Lab.
North of Lab is a locked door called a red door. South of Lab is a locked door called a blue door.
North of the red door is the Back. South of the blue door is the Front.

After pulling the lever:
if we have pulled the lever more than three times,
continue the action; [<-- goes to the default report rule (“Nothing obvious happens.”)]
otherwise say “[one of][option 1][or][option 2][or][option 3][in random order]”.

To say option 1:
now the red door is unlocked;
now the red door is open;
say “The red door opens.”

To say option 2:
now the blue door is unlocked;
now the blue door is open;
say “The blue door opens.”

To say option 3:
now the magic ball is off-stage;
say “The magic ball dissappears!”

test me with “n / s /pull lever / g / g / g / x magic ball / n / s / s”.[/code]

Oh yes, perfect. Thanks a ton.

D’oh. It took a while for the penny to drop, but Skinny Mike’s take on it does sound a lot more sensible.

Another question: is there some easy way to solve the he/she problem?

I could do “[if target is male]he[if target is female]she[end if] blah blah”, but is there a shorthand for that?

Hopefully this is not a dud as well, but

To say gender of (whoever - a person): say "[if whoever is male]he[otherwise if whoever is female]she[otherwise]it[end if]".

seems the simplest solution to me. Then you just invoke it as “[gender of target] blah blah” in any To Say phrase.

Emily Post’s Plurality handles the he/she problem.

:blush:

Wow, I had no idea that text substitutions could execute code - that’s like finding a magic wand down the back of the sofa! Thanks Skinny Mike.

One of my favorite tricks comes from John Clemens. Include this in your code:

To say @ (ph - a phrase): (- if (0==0) {ph} -)

You will now be able to insert any phrase into a text substitution, e.g.:

say "You look at your shoes. [run paragraph on][@ try the player examining the shoes]";

–Erik

Huh. Cute. Thanks.

Can you work quoted text into the phrase when you do that? Or does the parser still get grumpy about that?

That’s a great resource. Thanks, Erik!

Unfortunately, no. The I7 compiler doesn’t seem to be able to parse a quote within a bracket no matter what you do (the Mac IDE syntax coloring can’t deal with it either).

–Erik