Custom actions and stuff.


#1

I’m very new to this, but i want to make custom commands like “scream” or “push mat.” instead of look under. any help.
just in case this is what i have so far

[code]“first test” by R3M
Include Hidden Items by Krister Fundin.

[Front porch]
front porch is a room. “the house towers above you as you are blinded by the light reflecting from the windows.”

player is in front porch.

the welcome mat is scenery in front porch. the description is "a standard welcome mat that lies crooked on the ground. it has a small bulge in the middle "

a white door is a locked door. it is north of front porch and south of hallway. “a white door leads [if the player is in front porch]into the house[otherwise]outside[end if].”

the description of a white door is “a beautiful looking white door, apon closer inspection it seems handcrafted. a welcome mat lies crooked on the ground.”

a small key is a thing. the description is “a small golden key.”

a small key unlocks a white door.

instead of looking under the welcome mat for the first time:
move a small key to front porch;
say “you found a small golden key.”;

[Hallway]
hallway is a room.
“a beautiful hallway filled with statues and paintings.”
[/code]


(matt w) #2

Pushing is a built-in action so you don’t have to define it! You should probably still allow “look under mat” as a synonym though. One way to do that would be with a kind of action:

[code]Pushing the mat is moving the mat. Looking under the mat is moving the mat. Pulling the mat is moving the mat.

Instead of moving the mat for the first time…:[/code]

(In this the name of the kind of the action is “moving the mat”–the fact that “the mat” is part of the name doesn’t mean anything, it just makes it easier to keep track of.)

If you do want to make a custom command for a new action, then you need to define the action, define Understand lines for the commands leading to the action, and write rules for the action:

[code]Screaming is an action applying to nothing.

Understand “scream” as screaming.

Instead of screaming: say "Even if you’re outside, you can still use your inside voice.[/code]

Or for an action that takes a noun:

Lifting is an action applying to one thing. Understand "lift [something]" as lifting. Instead of lifting the welcome mat: try looking under the welcome mat. Instead of lifting something: try taking the noun.

(The more specific “instead” rule runs before the more general one, so this means “lift mat” turns into looking under the mat and “lift key” or anything else turns into taking it.)

Hope this helps! Also I am unable to use Inform to test the code right now so apologies if there is an error.


#3

I tried to apply that syntax to a “parking brake” device :

The Street  is a room.

A car is a thing in the street.
The parking brake is a device.
The parking brake  is part of the car.
The parking brake is switched on.
Switching off the parking brake is releasing the parking brake.

x car
You see nothing special about the car.

The car includes a parking brake.

switch the parking brake
You switch the parking brake off.

switch the parking brake
You switch the parking brake on.

release the parking brake
That’s not a verb I recognise.

release parking brake
That’s not a verb I recognise.

Short of reading and understanding all of “INFORM 7 The Program Complete Program Build 5Z71 Graham Nelson” (the NI compiler), is there another reference or source to understanding I7 ?

Mike


#4

What this does:

Switching off the parking brake is releasing the parking brake.

is actually defining “Switching off the parking brake” as a kind of action, as Matt suggested (see §7.15 in Writing With Inform), as in:

Saying yes is passive-aggressive behaviour. Saying sorry is passive-aggressive behaviour.
(“Saying yes” and “Saying sorry” already exist as actions.)

This, however, does not give the player permission to use “passive-aggressive behaviour” (or “releasing,” in your example) as a command. That’s why you get the “That’s not a verb I recognise.” response.

In order to use the “release” command as switcing, here is what you need to do:

The Street is a room.

A car is a thing in the street.

The parking brake is a device and a part of the car. The parking brake is switched on.

Understand "release [something]" as switching off.

(matt w) #5

[Giannis gave a much more succinct answer while I was typing. Here’s a very long-winded answer!]

Hi Mike! I would not recommend trying to understand Inform 7 by reading that at all… it’s a complete source code for the whole freaking compiler of an older version of Inform. (And I don’t think it was really supposed to be released, but I certainly have a copy on my computer just in case…)

The canonical reference for Inform is Writing with Inform, which is the manual that is built into the Inform app, and can also be found here. But that is a lot to read and is kind of eccentric in some ways. Don’t get me wrong–I learned the language by reading the manual over a long period of time and working through lots of the included examples. But it doesn’t work for everyone.

Carolyn VanEseltine’s QuickStart guide to Inform 7 is a good way to get started.

Anyway! For this particular issue, this has to do with Kinds of Action which are covered in WwI §7.15. The first important thing to understand is that in “Switching off the parking brake is releasing the parking brake” the two sides are not the same kind of thing at all. “Switching off the parking brake” is a description of an action, which consists of the action name “switching off” and the object “the parking brake.” (We could also have a more general description like “switching off something” or “switching off a device.”)

In this kind of declaration, “releasing the parking brake” is just the name of the kind of action and doesn’t have any logical parts. It could just as well be called “ReleasingTheParkingBrake,” or “poop di di scoop,” or something like that. It’s usable for making a rule that encompasses different actions all at once. So you can write this:

[code]The Street is a room.

A car is a thing in the street.
The parking brake is a device.
The parking brake is part of the car.
The parking brake is switched on.
Switching off the parking brake is releasing the parking brake.
Pulling the parking brake is releasing the parking brake.
Pushing the parking brake is releasing the parking brake.

Instead of releasing the parking brake, say “You’d roll downhill.”[/code]

and the Instead rule will work on all three of those actions. (You can verify that changing it to “poop di di scoop” doesn’t change the behavior, though it makes the code more confusing.)

If you want the player to be able to write the command “release parking brake,” the thing to do is to write a new “Understand” line. “Understand” lines are for things the player can type–kinds of action are just for the programmer’s internal use. This particular thing can be found in WwI §17.2, “New commands for old grammar”–which really means for old actions. If you write:

Understand "release [something]" as switching off.

then “release parking brake” will be understood as switching the parking brake off. Also “release flashlight” will be understood as switching the flashlight off.

That might be undesirable. We could take care of it by making a new action called releasing, and writing rules that redirect it appropriately. See WwI §12.7.

[code]Releasing is an action applying to one thing. Understand “release [something]” as releasing.

Instead of releasing the parking brake, try switching off the parking brake.
Instead of releasing something, try dropping the noun.[/code]

“Releasing is an action applying to one thing” defines the new action. The “Understand” line defines the command the player can type to invoke it. Then the Instead rules redirect it–the more specific one applies when the noun (basically the direct object) is the parking brake, and “try” redirects the action to switching off. For anything else, the less specific Instead rule applies, and the “try” redirects the action to dropping the noun, whatever it may be.

Hope this is somewhat helpful! There’s a lot to absorb with the language.


#6

You can also limit the action based on location so the same command does not cause an unwanted effect someplace else.

Understand "knock on [something]" as opening when the location is reception.

This would prevent knocking on something else as being an opening command, unless of course it is also in the room called reception.

Depends on what you need the limits to be. In the example mentioned it could be tied to the car, if the car is in a location and/or the player has to enter the car to reach the brake making the car a location.


(matt w) #7

Yes. The thing to be careful there, from a game design point of view, is that it can be disconcerting to the player if “knock on door” gets understood as “open door” in reception but gives a “That’s not a verb I recognise” error elsewhere. The player will assume it doesn’t work at all.

You can do something similar with nouns, like

Understand "release [the parking brake]" as switching off.

but again, if they try “release” on something else and it doesn’t work, they’ll assume “release” doesn’t work at all.

…on a test run, this did work:

Understand "release [the parking brake]" as switching off. Understand "release [something]" as dropping.

but I’m a bit wary of trying to trick the parser like that, for fear that by tampering with things that I do not understand I will release an ancient evil. (What I’m saying is that the internals of the parser are very complicated and I can’t guarantee that stuff like this will work consistently.)


(Andrew Plotkin) #8
Understand "release [the parking brake]" as switching off.
Understand "release [something]" as dropping.

The big thing you lose when you do this is disambiguation. Inform can’t ask a disambiguation question that spans grammar lines, so (for example) RELEASE HANDLE would just pick the parking brake instead of saying “Which do you mean, the parking brake or the dog leash handle?”