Conditional Statements: If And Now

(I tried to move this to the Inform7 forum. It ended up here. If you move it, would you please notify me)

I have the following rule:

Report lighting an unlit torch with a lit torch:
now the noun is lit;
say “You light [the noun] with [the second noun]. Now you can see some things in the chamber you couldn’t see before. Maybe you should look at the chamber again.”;
now the Yesod Key is revealed in Chamber of Creatures.

That works fine.

But I have torches and hidden keys in 8 other rooms; and I want the Keys in each room revealed only after the appropriate torch is lit.

For example, if the fifth torch is lit in the Wind Chamber, then the Tiferes Key is revealed.

I’ve tried attaching a series of if…otherwise statements of the following sort:
if noun is lit and room is Chamber of Creatures;
now the Yesod Key is revealed in Chamber of Creatures;
otherwise;
in noun is lit and room is Wind Chamber;
now the Tiferes Key is revealed in Wind Chamber.

But no matter how I punctuate it (or add begin; and end if.) I get various error messages.

Please advise.

You’re using semicolons interchangeably with colons. That won’t work: if statements and otherwise statements must be punctuated with a colon.

Could you be a bit more explicit, please. All of the examples I looked at used semicolons.

I’m assuming your indentation looks something like this:

if noun is lit and room is Chamber of Creatures; now the Yesod Key is revealed in Chamber of Creatures; otherwise; if noun is lit and room is Wind Chamber; now the Tiferes Key is revealed in Wind Chamber.

You’re using a semicolon after your “if” and “otherwise” statements. That doesn’t work. You want it to look like this:

if noun is lit and room is Chamber of Creatures: now the Yesod Key is revealed in Chamber of Creatures; otherwise if noun is lit and room is Wind Chamber: now the Tiferes Key is revealed in Wind Chamber.

I’m also going to caution you against using “room” as a variable name, since that’s probably not going to do what you want. If you want the room that the player is in, that’s the “location”.

OK, I gave it a try as you indicated. I entered:

If noun is lit and location is Chamber of Creatures:
now the Yesod Key is revealed in Chamber of Creatures;
otherwise if noun is lit and location is Wind Chamber:
now the Tiferes Key is revealed in Wind Chamber.

I got two errors:

  1. Something about indentation. But I checked to make sure that the nows were indented a tab not spaces. I’m not used to a computing language that differentiates between spaces and tabs.

  2. This one: (The way this sentence starts makes me think it might have been intended as part of a rule rather than being a statement about the the way things are at the beginning of play. For example, 'If the player is in the Penalty Zone, say “An alarm sounds.” is not allowed: it has to be put in the form of a rule showing Inform what circumstances apply - for example 'Every turn: if the player is in the Penalty Zone, say “An alarm sounds.”)

Is #2 in fact the case? If otherwise statements can’t stand alone.

That is indeed the case. This needs to be in a rule of some sort, which specifies when the condition should be checked. (It’s like in C; you can’t have an if-statement outside a function.)

So I tried this:

Check lighting it with:
if noun is lit and location is Chamber of Creatures:
now the Yesod Key is revealed in Chamber of Creatures;
otherwise if noun is lit and location is Wind Chamber:
now the Tiferes Key is revealed in Wind Chamber.

It compiled. But when I went to any, lit the torch there, and then >Look…the torch is lit but the Key is not revealed.

The check rules run at the beginning of the action, before whichever rule is lighting the torch. Thus the noun isn’t lit at the time the check rule runs.

Please keep in mind I’m a newbie. I took a look at the rule sequencing chart; left me even more confused.

Tried adding Every turn:
if noun is lit and location is Chamber of Creatures:
now the Yesod Key is revealed in Chamber of Creatures;
otherwise if noun is lit and location is Wind Chamber:
now the Tiferes Key is revealed in Wind Chamber.

But that failed. So maybe you could suggest a rule?

Here’s the way I’d handle this problem.

Every turn when there is a lit torch in the location and there is a hidden thing (called the item) in the location: say "Something sparkles in the light. It looks like [an item]."; now the item is revealed.

Like the idea. Tried it. Did not reveal key.

Could you post a minimal complete example that shows it not working?

Sure. Thank you for asking:
Welcome to Galmi’s Castle. The castle is surrounded by evil yetzer demons. You need Galmi’s help to stop them. But Galmi doesn’t seem to be alive. Discover how to bring him to life and save the castle from the demons.

Galmi’s Castle
An Interactive Fiction by Mooki Glicken
Release 1 / Serial number 180108 / Inform 7 build 6M62 (I6/v6.33 lib 6/12N) SD

Clay Chamber
You are in the Cellar at the bottom of the castle. It is damp and smells like clay. A torch on the north wall provides the chamber’s only light. There is a dark stairway next to it leading up.

You can see Galmi, an old sack (empty) and a burning wooden torch here.

take torch
Taken.

go up

Chamber of Creatures
You are on the 1st Floor of the castle. There are two stairways, one leading up and one down, and two doors, one going northeast and one northwest.

You can see an extinguished second torch here.

light second torch with wooden torch
You light the burning second torch with the burning wooden torch. Now you can see some things in the chamber you couldn’t see before. Maybe you should look at the chamber again.

look
Chamber of Creatures
You are on the 1st Floor of the castle. There are two stairways, one leading up and one down, and two doors, one going northeast and one northwest.

You can see a burning second torch here.

Here’s some of the relevant code:
The Yesod Key is a key. The Yesod Key is hidden in Chamber of Creatures. The description of the Yesod Key is “The Yesod Key is vitality for Galmi’s pelvis.”

Lighting it with is an action applying to two things.
Understand “light [something] with [something]” as lighting it with.

Check lighting it with:
if the player does not hold the second noun:
say “You’re not holding [the second noun].” instead.

Check lighting it with:
if noun is lit:
say “That torch is already lit. Try looking at the chamber to see what may now be visible.” instead.

Report lighting an unlit torch with a lit torch:
now the noun is lit;
say “You light [the noun] with [the second noun]. Now you can see some things in the chamber you couldn’t see before. Maybe you should look at the chamber again.”.

Every turn when there is a lit torch in the location and there is a hidden thing (called an item) in the location:
say “Something sparkles in the light. It looks like [an item].”;
now the item is revealed.

I think Draconis meant a working code example. Here’s one below that seems to do what you want:

A torch is a kind of thing. A torch can be lit.  
A wall-mounted torch is a kind of torch. A wall-mounted torch is usually fixed in place.
The initial appearance of a wall-mounted torch is usually "A torch [if lit]blazes[otherwise]sits[end if] affixed to the wall here."

A key is a kind of thing.
A room has an object called the requisite key.

Lighting it with is an action applying to two things. Understand "light [something] with [something preferably held]" as lighting it with.
Check lighting something which is not a torch with something: say "You don't think that will burn." instead.
Check lighting a lit torch with a lit torch: say "That's already on fire." instead.
Does the player mean lighting a wall-mounted torch with your torch: it is very likely.
Does the player mean taking something which is not fixed in place: it is very likely.

Carry out lighting an unlit torch with a lit torch: 
	now the noun is lit; 
	now the requisite key of the location is in the location.

Report lighting a torch with something: 
	say "You light [the noun] with [the second noun]. Now you can see some things in the chamber you couldn't see before. Maybe you should look at the chamber again."


The Chamber of Creatures is a room. The requisite key of the Chamber of Creatures is the Yesod Key.
There is a wall-mounted torch in the Chamber of Creatures.
The Yesod key is a key. "The Yesod key lies gleaming in the dust at your feet." The description of the Yesod key is "The Yesod Key is vitality for Galmi's pelvis."

The player holds a torch called your torch. Your torch is lit. Understand "your torch" as your torch.

Test me with "light torch with torch/look".

As an aside, I recommend posting your code within code tags, because that preserves indentation. Without that, the code is harder to decipher.

That’s a very different approach. I’ll give it a try.

A couple questions:

  1. What does “requisite” do? And how does the program know that “requisite key” is initially hidden?

  2. What is the “test me” code?

Thank you.

  1. “Requisite key” in this case is just label. In fact, I should probably have named the label something different in order to prevent confusion. What I do is, I give each room an object (that means you can check if it’s “nothing”, and if so, not attempt to do anything with it which would prevent a run-time error), and that associated object is then used when plucking the desired object from off-stage. As for why it’s off-stage to begin with, when you simply declare “there is an [x]”, or “an x is a thing”, that gives it no default location, and it is thus created off-stage.

  2. If you provide “test [anything]”, that allows you to run a test script. Try it by running the game and typing “test me”. Providing complete code with a test phrase allows a reader to quickly see the behavior for themselves.

Great. Very helpful. Thank you. I helping my grandson work through the revisions now. Back to you later if we encounter any snafus.