How do I start a scene when the player examines an object?
I had that exact same question.
The suggestions didn’t work for me. I suspect it was my code, as I never tried to compile it in a test game. Maybe you’ll have better luck with it.
My way to do this is to use a flag.
You create your scene, then you create a number variable. You have a ‘carry out’ rule for the action you want to launch the scene, which sets the flag to 1. You have the scene start condition be ‘when this flag is 1’. Then, the first thing the scene does when it goes off is set the flag to 2, to prevent a double launch. Once the scene’s over, the scene can either clear the flag (if you want the scene to be relaunchable) or ignore it, or whatever. The main point is - you can attach the flag to any action and it always works, regardless of whether rules failed, succeeded… it launches the scene when you set the flag to 1.
Here’s a demo game using a recurring scene with this method, so this scene you can launch again after it’s over, as many times as you want. Boot it up and type ‘test me’.
[code]“The Wrath of Explosionor” by Wade Clarke
There is a room called the Temple. “You’re in the temple. Everything in here looks dangerous. A sign says ‘HANDS OFF THE RELIC’.”
There is a supporter called the altar. The altar is in the temple. Description of altar is “It’s neat, but not as neat as that relic, you bet. You’re dying to examine the relic.”
The relic is on the altar.
The relic has a number called wrath_flag.
Instead of doing anything to relic:
if wrath_flag of relic is 2, say “Get real. With the Wrath of Explosionor occurring, you can’t examine the relic.”;
otherwise now wrath_flag of relic is 1. [launches the scene]
Wrath of Explosionor is a recurring scene.
Wrath of Explosionor begins when wrath_flag of relic is 1.
When Wrath of Explosionor begins:
now the wrath_flag of relic is 2; [prevents scene starting twice in a row]
say “A loud voice proclaims: ‘INTERLOPER! DARES’T LOOK AT MY RELIC? YOU HAVE INCURRED THE WRATH OF ME, EXPLOSIONOR! ENDURE MY WRATH FOR 2 TURNS!’”
Every turn during Wrath of Explosionor: say “You’re currently experiencing the Wrath of Explosionor, and believe me, it’s impressive, but it’s not actually killing you, thus you can continue to get on with your life.”
Wrath of Explosionor ends when the time since Wrath of Explosionor began is 2 minutes.
When Wrath of Explosionor ends:
say “Ah, the Wrath of Explosionor has passed. What a relief. But it could happen again! And that would suck.”;
now the wrath_flag of relic is 0.
test me with “x altar / x relic / wait / wait / get relic / wait / wait”.[/code]
Puh. I had to look up quite a lot of stuff on the way, but now it works, thanks to this flag solution. Muchas gracias!
[code]A thing can be examined. A thing is usually not examined.
After examining something:
now the noun is examined.[/code]
I find this bit of code to be very usefull, since it allows you to monitor if anything is or isn’t examined.
You have to be carefull, though: if, at some point of the source, you add an ‘After examining sock:’ thing and forget to add the ‘now the noun is examined’, then it will override the above code and your sock won’t be flagged as examined.
An ugly-looking, but precisely deployable, solution:
To say note-examined (T - thing): now T is examined. The description of the relic is "[note-examined relic]You recognize the Dagger of Foofaraw."
The “[note-examined relic]” substitution prints as nothing; it just sets the flag. You have to embed it in each description that counts as examining, but then you always know when one of them has triggered.
I find this useful when the same information can come in various ways. For example
Report taking the relic: say "[note-examined relic]You pick it up, and recognize the Dagger of Foofaraw."
All this flag nonsense is very AGT…
I developed my IF-writing habits in Inform 5. I like flags. If you can make scenes work for you, by all means use them.
I love flags. I wish they had a more… functional and direct use in Inform 7.
What are you talking about? They’ve got as much or as little use in Inform 7 as you want. My programming is extraordinarily flaggy. Just program the way that suits you best. Unless you indulge in outrageous inefficency en route, all roads that lead to the desired outcomes are good roads.
You can avoid that problem by using a carry out rule instead of an After rule:
Carry out examining something:
now the noun is examined.
You still have to worry about Instead, though.
I never thought of tweeking the carry out rule because I always avoid doing it to established actions, since I’m kind of afraid of messing something up that I’m not aware of.
But I’ve followed your cue and it works better. The ‘insteads’ are not a problem for me, since I almost only use them when the action is supposed to fail.
Check rules can be tricky that way, but carry out rules are usually pretty straightfoward. The only thing you really need to worry about is order. Some actions are simple, but with going, for example, you’ll be in a different room depending on when the carry out rule fires. In fact, order is really the only issue with check rules - what makes it tricky is that there are more of them and some of them stop the action or trigger other actions. But carry out rules should never stop the action, and they probably shouldn’t trigger any actions either.