Five Coding Questions in Inform 7

Like “move player to Dank Cellar”, “if the player is in the sewer” needs to be inside a rule or phrase; otherwise Inform doesn’t know what to do with it. You could create a Rat Attack scene and put your code in a “When Rat Attack begins” rule, but in this case that would be overkill. Here’s how I’d do it:

Every turn when the player is in the Sewer and the giant rat is in the Sewer: if in darkness: say "The gleaming eyes of a giant rat peer from the out the darkness. Scuttling your way with startling speed, it launches itself upon you and gnaws a gaping hole into your neck. In death, your body is eaten over the course of several weeks."; end the game in death; otherwise if the cat is in the Sewer: say "The giant rat and cat fight each other to the death."; remove giant rat from play; remove cat from play; move rat corpse to Sewer; move cat corpse to Sewer; otherwise: say "A giant rat kills you."; end the game in death.
There are a few things to note here:

  • “If the sewer is dark” will be true even the player is carrying a light; it tests whether the room itself is lit, not whether something is lighting the room. You need to use “if in darkness” instead.
  • With your code, the giant rat will kill the player any time the Sewer is lit, whether or not the cat is in the Sewer. Putting the cat-and-rat-kill-each-other section before the rat-kills-player section fixes this.
  • “End game” isn’t a phrase Inform understands. You have to use “end the game in death”, “end the game in victory”, or "end the game saying “some text”’.
  • You can’t move more than one thing at once by saying “remove the giant rat and the cat from play” or “move rat corpse and cat corpse to sewer”. You have to move them separately.
  • “If” statements in square brackets, like “[if lit]”, can only be used inside blocks of text, like “say “The fridge is [if the fridge is open]open[otherwise]closed.””. Outside a block of text, anything in square brackets will be interpreted as a comment and ignored.

Emerald, you have saved my interactive fiction buttocks again. I will repay you one day in the delights of the flesh…

By which I mean, I will give you a cannibal feast at the source of the Congo.

Okay, another wee problem:

In the beginning, my main character is thrown into a Dank Cellar to die by thirst in utter darkness. Little do they know, but he has a hidden match in his hair which permits him light (and therefore the ability to solve a puzzle to get out of the locked room).

The problem, though: Is when I code the match, it doesn’t apparently continue to light the way if I go into another room.

Now I used the torch in the manual and that seems okay, but it doesn’t permit me to extinguish or light the torch (which I’d change to a match). How might I make the torch lightable? Do I make it into a device? When I made the match lightable as a device originally, it didn’t work out.

Here are the two codes:

Torch from the manual:

[code]A torch is kind of thing. Understand the lit property as describing a torch. Understand “lighted” or “flaming” or “burning” as lit. Understand “extinguished” as unlit. A torch is usually lit.

Before printing the name of a lit torch, say "flaming ".
Before printing the name of an unlit torch, say "extinguished ".

The player carries a torch.[/code]

My half-original code:

[code]A match is kind of device. Understand the lit property as describing a match. Understand “lighted” or “flaming” or “burning” as lit. Understand “extinguished” as unlit.

Before printing the name of a lit match, say "flaming ".
Before printing the name of an an unlit match, say "extinguished ".

Carry out switching on match: now the location is not in darkness.

Carry out switching off match:
if in darkness:
say “Darkness cloaks the room.”
otherwise:
say “The acrid smell of an extinguished match fills your nostrils.”

A hidden match is carried by the player. A hidden match is a match. The hidden match is switched off. Hidden match is portable. The description is “A match originally hidden in Arverus [’] hair.”[/code]

I get an error with this that says

The phrase or rule definition 'Carry out switching off match'   is written using the 'colon and indentation' syntax for its 'if's, 'repeat's and 'while's, where blocks of phrases grouped together are indented one tab step inward from the 'if ...:' or similar phrase to which they belong. But the phrase 'if in darkness'  , which ought to begin a block, is immediately followed by <no text> at the same or a lower indentation, so the block seems to be empty - this must mean there has been a mistake in indenting the phrases.

My original version didn’t get an error but had the problem:

[code]A match is kind of device. Understand the lit property as describing a match. Understand “lighted” or “flaming” or “burning” as lit. Understand

“extinguished” as unlit.

Before printing the name of a lit match, say "flaming ".
Before printing the name of an an unlit match, say "extinguished ".

The match is a switched off device.

Carry out switching on match: now the location is lit.

Carry out switching off match: [if the room is dark] say "Darkness cloaks

the room."; [otherwise] say "The acrid smell of an extinguished match fills

your nostrils."

A hidden match is carried by the player. A hidden match is a match. Hidden

match is portable. The description is "A match originally hidden in Arverus

[’] hair."[/code]

Haven’t looked over your whole code, but this jumps out:

Objects can be lit or unlit, rooms can be lighted or dark. This is explained in ch 3.15, but can be more easily discovered by consulting the “kinds” page of the index tab. (In general, the index is an invaluable tool. There have been several posts, here and on raif, from authors including myself that indicate that using the index tabs leads to a quantum leap in understanding I7.)

The use of two different properties to describe what seems to be the same thing might seem like silly at first, but it has to do with the way Inform handles light. Rooms cast light inward, or down the “object tree” toward the player. Objects cast light outward, or up the tree. (If the player is in a lighted room, but inside an opaque container, they are in darkness. If they carry a lit flashlight and put it inside a transparent platic bag, they are in light.)

To get back to your issue then, if you want the match to light a room, just cause the match to be lit, and don’t worry about making the room lighted – that will happen automatically, provided the match is in proper position (i.e. not inside a closed, opaque container). So you could change the above to:

Carry out switching on match: now the match is lit. … but I wouldn’t do that. Why mess with devices unless you really want the player to be able to “Turn on match?” Better to make a striking action (You’ve already got practice creating actions. :slight_smile: ) Then you could just: Carry out striking the match: now the noun is lit. Hope that all makes sense.

Thanks so much! I will go and code that in post haste.

Also, thanks for the tip on the index. But how do you access it? When I click on it, everything remains blank.

Oh yeah, this is a common question that I forgot to address. The index is designed to index the current compiled project. It is created and/or updated every time you hit “Go” and the project compiles successfully. This makes sense; you normally want to know the actions, objects, rules, etc. for the game you’re working on right now, not some generic template game. The problem is, sometimes you need a generic game to get you started finding things. I still start every project with one room (“The lab is a room.”) and hit “go” immediately before doing anything else. This gives me an index to work with.

Many thanks!

I feel sexy.

VERY sexy.

[code]Striking is an action applying to one carried thing.

Understand “strike [thing]” as striking.
Understand “light [thing]” as striking.

Check striking (this is the only strike matches rule):
unless the noun is a match, say “you can’t strike [noun]”

Carry out striking:
Carry out striking the match: now the match is lit.[/code]

Works!

I made something better. This allows me to make all sorts of lightable things (lanterns, lamps, penises…wait, what?). Also, a sister command is “douse”.

Both are provided here:

[code]Part Lighting Command

A lightable is a kind of thing.

Lighting is an action applying to one carried thing.
Understand “light [thing]” as lighting.
Understand “ignite [thing]” as lighting.
Understand “strike [thing]” as lighting.

Check lighting (this is the only light a lightable rule):
unless the noun is a lightable, say “you can’t light [noun]”

Carry out lighting:
Carry out lighting the noun: now the noun is lit.

Part Dousing Command

Dousing is an action applying to one carried thing.
Understand “snuff [thing]” as dousing.
Understand “extinguish [thing]” as dousing.
Understand “douse [thing]” as dousing.

Check dousing (this is the only douse lightables rule):
unless the noun is a lightable, say “you can’t douse [noun]”

Carry out dousing:
Carry out dousing the noun: now the noun is unlit.[/code]

I am having a bit of problems with this command.

The code has no problems, but it doesn’t seem to work right. I think there is something I am overlooking, but I can’t find it yet.

[code]Part Second Sight Command

A makesghostsappear is a kind of thing.

Secondsighting is an action applying to things.
Understand “open the cat-corpse’s eyes” as secondsighting.

Check secondsighting (this is the only makesghostsappear uses second-sight rule):
unless the noun is a makesghostsappear, say “you cannot open [noun][apostrophe]s eyes”

Check secondsighting (this is the only time you can use second sighting is dropping the cat-corpse in the steward’s room rule):
unless the noun is in the Steward’s Room, say “there is no ghosts to be seen.”

Carry out secondsighting:
Carry out secondsighting the noun: move the Steward’s Ghost to the Steward’s Room.[/code]

The problem: When I try to open the cat-corpse’s eyes, it says “you must supply a noun” in the game window.

Well, first off:

The action definition and the grammar should (almost) always agree. (There are times when you can get around this with special rules for supplying a missing noun, but this isn’t really one of those times.) The action you want applies to one thing. “One thing” in this context means “one thing at a time” – even “taking” which can have multiple objects is defined as applying to one thing. So your gammar line should contain a noun text substitution in brackets, like [something] or [cat-corpse]. This almost works:Secondsighting is an action applying to one thing. Understand "open [something]'s eyes" as secondsighting.The problem is apostrophes in grammar statements tend to mess up the mechanism. Notice the output depending on whether or not I put a space before “'s”:

Also, you’ve got some redundant code in the carry out rule. I’m not even really sure why it compiles, but all you need is:Carry out secondsighting: move the Steward's Ghost to the Steward's Room.I think I have an easier solution involving the opening action, but mess with that in the meantime and see if it helps.

Okay, forget the opening action, let’s just stick with your secondsighting action. Inform understands apostrophes best when the are refering to parts of what are called assemblies (see ch 4.5. Assemblies and body parts). This is when you’ve got a generic kind of thing – like a body part – which is a part of another kind of thing. Even if you only want the one corpse, you can make it a kind of thing, which always has a part which is another kind of thing (the eyes) and inform will properly understand “cat corpse’s eyes”:[code]A corpse is a kind of thing. The eyes are a kind of thing. The eyes are a part of every corpse.

The cat corpse is a corpse in the Steward’s Room.
Understand “cat’s eyes” as the cat corpse’s eyes when the cat corpse is visible.[/code]Note that you need that last line because “cat corpse’s eyes,” “corpse’s eyes,” and even “eyes” are understood automatically, but not “cat’s eyes.”

Next, the secondsighting action:Secondsighting is an action applying to one thing. Understand "open [eyes]" as secondsighting.Since we use “[eyes]” in the grammar line, those are the only kinds of direct objects to the secondsighting action. You want to do it this way since you want still want “open [something]” to be able to open doors, etc. Note that this means you can leave out the check rule for the “makesghostsappear” kind of thing, since things that are not a kind of eyes will go to the open action and be rejected there if the noun is not openable. Finally:[code]Check secondsighting (this is the only time you can use second sighting is dropping the cat-corpse in the steward’s room rule):
unless the location is the Steward’s Room, say “There are no ghosts to be seen.”

Carry out secondsighting:
move the Steward’s Ghost to the Steward’s Room.

Report secondsighting:
say “The Steward’s Ghost appears!”[/code]I think that does what you need.

Edit: Note that if you give corpses eyes, you’ll probably want to give them to every person (including yourself). Players will find it odd as well as bad form if the only eyes in the whole game that can be examined or interacted with are the dead cat’s. See ex.48 for an example involving noses.

Dude. You are the man! Thank you so much.

I am going to apply that code ASAP.

One quick question:

Why is this giving me an error?

The description is "A curious compendium of four-pannelled comics. The problem being, of course, is that none of them are very funny. Bizarre - yes. Offensive - most certainly. Perplexing - to the extreme. Inane - of course. But funny? No! Are there seriously fans of this comedy? Truly, Dr[.] Satan Dracula was one odd duck of a scholar."

Problem. You wrote ‘The description is “A curious compendium of four-panne […] ula was one odd duck of a scholar.”’ : but a substitution contains a ‘.’, ‘:’ or ‘;’, which suggests that a close square bracket ‘]’ may have gone astray.

But…there are no ‘.’ ‘:’ or ‘;’ without brackets there…

I even tried doing:

Holier than Thou Featuring Dr[.] Satan Dracula is a book. The description is "A curious compendium of four-pannelled comics. The problem being, of course, is that none of them are very funny. Bizarre [-] yes. Offensive [-] most certainly. Perplexing [-] to the extreme. Inane [-] of course. But funny? No! Are there seriously fans of this comedy? Truly, Dr[.] Satan Dracula was one odd duck of a scholar."

But to no avail.

Never mind! Fixed it.

“[.]” and “[-]” are not valid text substitutions. The only reason I7 provides us with a built-in sub for the apostrophe is because authors need some way of using quotation marks. For example, if we want to print out:

We have to have an easy way to put quotes inside of quotes without confusing inform. We could do this:... say "Smokey says, [quotation mark]Only you can prevent forest fires.[quotation mark]"… but since that’s a common need, we’re given the option of using apostrophes as a shortcut:... say "Smokey says, 'Only you can prevent forest fires.'"Of course, when you actually need an apostrophe, we need something else, so we get to use either “[apostrophe]” or “[']”. See point #4 in ch 5.14.

Thanks again! I figured that out through trial and error of changing things.

Okay, now this is going to be a bit harder…

NOw that the ghost is all in the right place and such, I want the ghost to react to the player differently based on whether he is wearing a different outfit. Spread throughout the game will be provisionally three outfits. A servant’s, a lord’s, and a lady’s. If the player is not wearing one of these three, the ghost will kill them.

I am going to fiddle around and see if I can make this happen based off the rat attack thing. In fact, that might be the perfect basis for doing a code on this…

Every turn when the player is in the Steward's Room and the Steward's Ghost is in the Steward's Room: if the player is not wearing the servant's uniform, lord's clothes, or the lady's clothes: say "Get out intruder!"; end the game in death; otherwise if the player is wearing the servant's uniform: say "Oh, Buckley! There you are!"; otherwise if the player is wearing the lord's clothes: say "My lord!"; otherwise if the player is wearing the lady's clothes: say "My lady!"

That is my code so far. The problem is:

Problem. You wrote 'The first turn when the player is in the Steward's Room and the Steward's Ghost is in the Steward's Room'  : but the punctuation here ':' makes me think this should be a definition of a phrase and it doesn't begin as it should, with either 'To' (e.g. 'To flood the riverplain:'), 'Definition:', a name for a rule (e.g. 'This is the devilishly cunning rule:'), 'At' plus a time (e.g. 'At 11:12 PM:' or 'At the time when the clock chimes') or the name of a rulebook followed by some description of the current action (e.g. 'Instead of taking something:').

What should I put in place of the first line to make it work? I also want it to work every other time the player enters the room thenceforth, until all the items he’ll request (the three main quests) are given to him. After which, I want to change his reactions to the quest after that.

I changed things around…but now I am getting some new errors.

[code]In Part Third Floor, Chapter Steward’s Room:

Problem. You wrote ‘if the player is not wearing the servant’s uniform, lord’s clothes, or the lady’s clothes begin’ : but this is a phrase which I don’t recognise, possibly because it is one you meant to define but never got round to, or because the wording is wrong (see the Phrasebook section of the Index to check). Alternatively, it may be that the text immediately previous to this was a definition whose ending, normally a full stop, is missing?

Problem. ‘otherwise if the player is wearing the servant’s uniform’ makes sense only inside a ‘if … end if’ block.

Problem. ‘otherwise if the player is wearing the lord’s clothes’ makes sense only inside a ‘if … end if’ block.

Problem. ‘otherwise if the player is wearing the lady’s clothes’ makes sense only inside a ‘if … end if’ block.[/code]

A bit more complicated than I hope. Where am I getting it wrong?

By the way: My code should be properly indented. In the game, it is.

Fixed it. :slight_smile:

This is succesful:

[code]Every turn when the player is in the Steward’s Room and the Steward’s Ghost is in the Steward’s Room:
if the player is not wearing the servant’s uniform or not wearing the lord’s clothes or not wearing the lady’s clothes:
say “Get out intruder!”;
end the game in death;
otherwise if the player is wearing the servant’s uniform:
say “Oh, Buckley! There you are!”;
otherwise if the player is wearing the lord’s clothes:
say “My lord!”;
otherwise if the player is wearing the lady’s clothes:
say “My lady!”

The lady’s clothes is a thing. The lady’s clothes is wearable.

The lord’s clothes is a thing. The lord’s clothes is wearable.[/code]

However…

I just realized it is not recognizing the command “if the player is wearing the servant’s uniform”. IN as much as the ghost just killed me, despite the fact that I am wearing the servant’s uniform.

As I have no error message, what should I do?

Use “and” in the if statement, not “or”:

if the player is not wearing the servant's uniform and not wearing the  lord's clothes and not wearing the lady's clothes:

At the moment, Inform is reading the line as saying, “If any of these three things is true, do this stuff”, and since two of them are true (you’re not wearing the lord’s clothes and you’re not wearing the lady’s clothes), it’s doing that stuff. “And” tells Inform that they all have to be true before it does that stuff.