Pushing a button to open a door

#1

Hi everyone,
I’m a very new Inform 7 user and to be honest the syntax is very confusing to me so this is probably simple to do but I can’t figure it out.

I need to have a door that starts closed and un-openable. Then, the player presses a button in the room which opens the door. The door then remains open for the rest of the game.

I don’t even know enough to figure out if I have to define for Inform what the verb “press” means (I know “push” is already used for moving objects around the room).
This is for a college project, and earlier in the year we worked with the Twine and Quest engines and I had no trouble understanding how to create fairly complex interactions. I don’t know why Inform is so confusing for me.
Any help would be greatly appreciated!

0 Likes

(matt w) #2

Actually the pushing action is defined as what you want. (Moving objects around is a different action, called “pushing it to.”) So you can do this:

[code]Lab is a room. Foyer is a room.

The blue door is a door. It is north of Lab and south of Foyer. It is closed and unopenable.

The blue button is in Lab. It is fixed in place.

Instead of pushing the blue button when the blue door is closed:
say “The blue door slides open.”;
now the blue door is open.[/code]

If you want to know which actions are built-in and how to refer to them, the Index is very helpful, particularly the “Actions” tab. This lists actions various ways–grouped by various characteristics, alphabetic by the name of the action, and alphabetic by the commands used to invoke the action (also two other ways you don’t want to worry about now).

The difference between the name of the action and the name of the command is particularly important here. If you go to the “Commands” listing and look at “push,” you will see this:

This indicates that there are two different actions that can be invoked by a command starting PUSH. If you type PUSH BUTTON that invokes the pushing action, which we just used. If you type PUSH CART WEST or PUSH CART TO WEST that invokes the pushing it to action, which gets referred to in the source code as “pushing the car to the west.”

And if you click on the magnifying glass next to the action, you get a more detailed description, which can be helpful. In particular, it will give you the commands you can use to invoke the action. For pushing you get:

Which means that PRESS BUTTON will also work. (As well as weird things like SHIFT BUTTON and CLEAR BUTTON. I think this is because all those words are defined as global synonyms for “push,” in case the player wants to say something like SHIFT CART WEST. It should be harmless to leave them in for the pushing action.)

0 Likes

#3

That is correct. From the Standard Rules:

Understand "push [something]" as pushing.
Understand "push [something] [direction]" or "push [something] to [direction]" as pushing it to.
Understand the commands "move", "shift", "clear" and "press" as "push".
0 Likes

#4

Thank you so much! This really helped.

On a related note, how would I make it so that a door can only be opened if two separate switches are switched on? Normally I would use an if statement checking whether the switches are both on, but I’m not sure how to phrase that for Inform. I only got as far as:

[code]Antechamber is a room. Foyer is a room. Metal Door is a door. It is closed and unopenable. It is east of Antechamber and west of Foyer.

A Blue switch and a Green switch are in the Antechamber.

Instead of opening the metal door:
if the blue switch is off:
say “The door cannot be opened.”[/code]

Apparently “if the blue switch is off” doesn’t compile, and the documentation isn’t helping me figure out what’s wrong with it. Are switches not already defined as having the states “on” and “off”? How would I define that for Inform? It seems I’m not understanding how Inform thinks about objects and their properties.

Obviously I also need a way to simultaneously check the state of two separate switches and return a result only if both are on. How would I do that?

0 Likes

(Daniel Stelzer) #5

The states are called “switched on” and “switched off”, to avoid confusion with “on the table” and similar phrases.

Instead of opening the metal door when the blue switch is switched off or the red switch is switched off:
0 Likes