Stopping the player from entering the room

I am using Emily Short’s Basic Screen Effects to make a custom upper border for my game. On the right side of that, I have a “compass rose” that displays the room’s exits (like in Bronze, but without the “unvisited room” tracking). To create the illusion of a larger area, I have created an extra room, which I link the edge rooms to. I don’t want the player to enter this room, though, so I have written the following code to try to stop him.

Instead of entering Extension: if the player is in the Plains: say "The plains continue as far as you can see in that direction, and there is nothing for you there."; stop the action; if the player is in the Gorge: say "The gorge seems to go on forever. You would be better served to just climb out to the plains."; stop the action;Unfortunately, while this does not cause any errors, it seems to have no effect. Am I doing something wrong (I know that “Instead” does the same thing as “stop the action”)?

“Entering” is the action of moving the player into a container or onto a supporter. “Going” is the action that gets you from one room to another. (For example, if you enter a door, the action is converted to going.) Based on your description of the setup (that is, assuming that “Extension” is the name of your out of bounds room), this should work. (See ch 7.13. “Going from, going to” of the docs.):Instead of going to Extension: if the player is in the Plains: say "The plains continue as far as you can see in that direction, and there is nothing for you there."; if the player is in the Gorge: say "The gorge seems to go on forever. You would be better served to just climb out to the plains.".

Thanks! It works now! However, I have run into another problem. I want the game to preform special code on the first time the player enters a room. I am currently using the following code.

Before entering Woods Entrance: if the scene number is 1: now the scene number is 2; say "You run under the trees, barely making it in before the ground behind you is soaked."; else: continue the action.“scene number” is a numeric variable that I am using to keep track of the part of the game the player is in (as you can see, this is still close to the beginning). The “else” is in there for later, if I want to include more events. Unfortunately, this code does not run. What am I missing?

EDIT: I just found an example (page 52 of the Inform Handbook) that might work in this case, as the player can only enter “Woods Entrance” at this point from one other room. However, what should I do if I want to have something like this later, where the room has multiple entrances?

The problem is probably the same as earlier: the action is not “entering” but “going to”. You could also use the “for the first time” structure (see chapter 7.16 in the manual):

Before going to the Woods Entrance for the first time: say "You run under the trees, barely making it in before the ground behind you is soaked."
By the way, you are aware that you don’t need to use a variable to track scenes since Inform has built-in scene management (chapter 10)?

Thanks, it works! I didn’t want to use “for the first time” because this room is the main “bridge” to the area where most of the game takes place, and it is very likely that I will put another event here. My “scene number” variable is somewhat different than the built-in scene, functioning more like chapter numbers in a book. I also use it to print a suitable heading in the status bar (if scene number is one, say…), which I don’t believe is something that Inform’s scenes can do.

You can have multiple before rules without them interfering with each other, for example

[code]Before going to the Woods Entrance for the first time:
say “You run under the trees, barely making it in before the ground behind you is soaked.”

Before going to the Woods Entrance when the player carries the flashlight:
say “You manage to lose your flashlight.”;
remove the flashlight from play.[/code]

The flashlight rule would always run when the player has the flashlight, regardless of whether the “for the first time” rule would run.

Well if you use “if scene number is one, say…” that’s not much different from doing “If Crossing the Woods is happening, say…” But you actually can attach text to scenes. For example like this:

[code]A scene has some text that varies called heading. The heading of a scene is usually “”.

Crossing the Woods is a scene. The heading of Crossing the Woods is “Chapter 1: Crossing the Woods”.
Crossing the Woods begins when play begins. Crossing the Woods ends when Meeting the Werewolf begins.
Meeting the Werewolf is a scene. The heading of Meeting the Werewolf is “Chapter 2: Meeting the Werewolf”.
Meeting the Werewolf begins when the time since Crossing the Woods began is 3 minutes.

To decide which text is the current heading:
repeat with x running through scenes:
if x is happening and the heading of x is not “”, decide on heading of x;
decide on “”.

When play begins:
change the left hand status line to “[current heading]”.

Test me with “z/z/z”[/code]

Scenes give much more flexibility than a single variable, but if that’s enough for your needs there’s nothing stopping you from using that approach.

I just think it is easier (just a matter of personal preference) to read the code:

Before going to the Woods Entrance: if the scene number is 1: say "You run under the trees, barely making it in before the ground behind you is soaked." otherwise if the player carries the flashlight: say "You manage to lose your flashlight."; remove the flashlight from play.

The problem that I thought that I might run into there was having multiple scenes running at the same time, and only one space to display the text. I might use it if I need more flexibility in the future, but for this game, that one variable works nicely.

I have run into another problem, though (error and code below).

Instead of taking the lightbulb from the lamp: if the lightbulb is not in the lamp: say "The socket is empty, so you cannot remove it from the lamp." otherwise: say "You [if the lamp is switched on]turn off the lamp, and [end if]unscrew the lightbulb."; now the lamp is switched off; silently try taking the lightbulb.

There’s a semicolon missing from the end of the third line.

That takes care of the error message you had, but the code still wouldn’t work for a number of reasons:

  • the action is wrong again, it should be “removing it from”. (The debug command ACTIONS is useful for finding out what are the “real” actions that the parser understands.)
  • if the player types GET LIGHTBULB instead of GET LIGHTBULB FROM LAMP, the rule won’t run.
  • if the player types GET LIGHTBULB FROM LAMP when the bulb is not in the lamp, the rule won’t run either. This is because the command is then parsed as taking an object called “lightbulb from lamp”.

The easiest way to solve all but the last point is:

After taking the lightbulb when the lightbulb was in the lamp: say "You [if the lamp is switched on]turn off the lamp, and [end if]unscrew the lightbulb."; now the lamp is switched off.
Fixing the last point is a bit trickier and possibly more hassle than it’s worth.

Punctuation…one of the hardest things in Inform. I want that rule to run only when the player is taking the lightbulb from the lamp, and the action to run normally every other time. Are you saying that it might not run even then? Also, I found that a device cannot also be a container. I solved this by making the socket an Inform-recognized part of the light, but want to redirect everything except examining it to the main lamp. Would I use something like the following? Instead of doing something other than examining with the socket: try doing it to the lamp.

EDIT: Never mind, I found the solution to this in Example 85 (“Fine Laid”):Before doing something other than examining when the current action involves the socket: if the socket is the noun, change the noun to the lamp; if the socket is the second noun, change the second noun to the lamp; try the current action instead.

It looks like you’ve got your solution using component parts, but I just wanted to comment on the above since this isssue comes up now and then. There are sometimes cases where an author feels stymied because Inform doesn’t allow “multiple inheritence” – that is, something can’t be a member of two different mutually exclusive kinds (like container and device). In almost all cases we can get around this using properties. If you look at the “kinds” index, you’ll see that a device is like any other thing except that it has an additional property; it can be switched on or switched off. If you want to create something which can be switched on/off but isn’t a device, it’s as simple as giving it this property:The lamp is a container in the Lab. The lamp can be switched on.Now the lamp will be a container that also responds appropriately to the switching it on / off actions. I’m not saying you should do that in this case, just that it’s a good thing to keep in mind.

That’s a good tip! Thanks! Now, another question. I would like to keep track of the player’s moves purely through a time (of day)-based system, and would like to change the ending screen to show the amount of time taken, instead of the number of turns. Also, I would like the time to show up only after the first “scene” has ended (scene number is greater than 1). Is there any way to do this without completely rewriting the obituary, as described on page 17.36 of the Documentation?

Try the following and you’ll see what I mean:

[code]The lamp shop is a room. The light bulb is in the lamp shop. The antique lamp and the modern lamp are containers in the lamp shop.

Instead of removing the light bulb from the antique lamp:
say “Light bulb removed from the antique lamp.”;
silently try taking the light bulb.

After taking the light bulb when the light bulb was in the modern lamp:
say “Light bulb removed from the modern lamp.”

Test me with “get bulb/put bulb in antique lamp/get bulb/put bulb in antique lamp/get bulb from antique lamp/put bulb in modern lamp/get bulb/put bulb in modern lamp/get bulb from modern lamp”[/code]

The antique lamp uses “removing it from”, the modern lamp uses “taking”. The difference is that “removing it from” applies only when the player types TAKE BULB FROM LAMP, but not when they type TAKE BULB (when the bulb is in the lamp), and it is likely that most players use the shorter version of the command. When the bulb is not in a lamp taking is not affected at all.

I believe that, after I posted that question, I did test your suggestion, as it now uses “taking”.