Help with defining new actions.

Hi, yet another question.

Basically I want to have a memory stick that the player can plug into various devices (the only devices in the game are computers). However, Inform doesn’t like my code:

[code]A memory container is a kind of container.

Plugging is an action applying to one memory container and one device. Understand “plug memory stick into [device]” as plugging. Carry out plugging a memory container into a device: now the memory stick is plugged into the device.

A check plugging rule: if the memory stick is not carried then say “You can’t plug your memory stick into something without actually having your memory stick!” instead.

Report plugging: say “[one of]You shove the memory stick into [the device][or]You plug in the memory stick.[cycling]”
[/code]

It keeps on saying this:

This problem is due to a confusing restriction that Inform imposes. Basically, in your action definition, you are only allowed to use a restricted set of terms, “thing” and “value” being the most common. So, instead of:

Plugging is an action applying to one memory container and one device.

…you need:

Plugging is an action applying to two things.

The grammar line (“Understand…as plugging”) is where you refer to more specific kinds or objects. Actually, your grammar line is also malformed. Because you defined the action as applying to two things, Inform will be expecting two bracketed terms, one for each of those things. Yours refers to only one thing; the reference to “the memory stick” in the grammar line is literal text will force the player to type exactly those words. Here’s what you want:

Understand "plug [a memory container] into [device]" as plugging.

Now the player can refer to any memory container, and can also refer to just “memory” or “the stick” or “stick” or whatever.

A couple more tips:

(1) You can write more specific rules if you call the action “plugging it into”. Inform will then understand rules that specify the objects, e.g. “Instead of plugging the shiny memory stick into the Macintosh”…

(2) Your code will be more reusable and easier to maintain if you use bracketed tokens to refer to objects, rather than just writing their names. Here’s the report rule redone (also, note that you need to use “the noun” and “the second noun” to refer back to the objects the player typed):

Report plugging: say "[one of]You shove [the noun] into [the second noun][or]You plug in [the noun].[cycling]"

This way, if you decide to add a second memory container called the flash drive, you don’t have to rewrite your code. Ditto if you decide to change the name of the memory stick. Inform will automatically insert the correct name.

Hope this helps.

–Erik

Thanks a lot!

You guys are really helpful over here, especially to newbies like me.

Meh, I’ve run into a new problem.

Inform doesn’t like this:

Carry out plugging a memory container into a device: now [the memory container] is plugged into [the device].

First, lose the brackets. They are used only in printed text, everywhere else they are comments that are ignored by the compiler. Second, you must use “noun” and “second noun” to refer to the things in question in this case.

Carry out plugging a memory container into a device: now the noun is plugged into the second noun.
This all assumes, of course, that you have defined a “plugged into” relation somewhere else in the code…

Another problem is that if you have an action that applies to two objects rather than one, you need to define your action to contain the word “it” – which is where the first object will go. So for instance:

Plugging it into is an action applying to two things. Understand “plug [something] into [something]” as plugging it into.

Only when Inform knows about “into” will it let you write a carry out rule that starts with “Carry out plugging a memory container into a device: …”.

I did what you guys said, but it still won’t work:

[code]
A memory is a kind of thing. The plural of memory is memories.

A memory container is a kind of container. It can only hold memories.

The memory stick is a memory container.

Plugging it into is an action applying to two things. Understand “plug [a memory container] into [a device]” as plugging it into.
Carry out plugging a memory container into a device:
now the noun is plugged into the second noun.

A check plugging it into rule: if the memory stick is not carried then say “You can’t plug your memory stick into something without actually having your memory stick!” instead.

Report plugging: say “[one of]You shove [the noun] into [the second noun][or]You plug in [the noun].[cycling]”[/code]

That’s all the code relating to the memory stick. It looks like it should work, but Inform keeps on saying this:

If you read that compiler error closely, it means Inform doesn’t really understand what it means for one thing to be “plugged into” something else. The source of Inform’s confusion is the ambiguity of the phrases you’re using. It makes sense to you or I that plugging something into something (an action) results in two things being plugged into each other (a state of being). Inform can’t understand that, though, on its own.

What you need to do is add some kind of state you can check (for example, “connected”) that is effected when the action of plugging one thing into something else is taken. This would depend on your story and what you want to accomplish, but for example you could have something like:

[code]The testarea is a room.

A memory is a kind of thing. The plural of memory is memories.

A memory container is a kind of container. It can only hold memories.

A thing can be connected. A thing is usually not connected.

The memory stick is a memory container in the testarea.

Plugging it into is an action applying to two things. Understand “plug [a memory container] into [a device]” as plugging it into.

Carry out plugging a memory container into a device:
now the noun is connected;
now the second noun is connected.

A check plugging it into rule: if the memory stick is not carried then say “You can’t plug your memory stick into something without actually having your memory stick!” instead.

Check plugging something into something:
if the noun is connected:
say “[The noun] is already plugged in.” instead;
if the second noun is connected:
say “Something is already plugged into [the second noun].” instead;
if the second noun is not the computer:
say “You can’t plug [the noun] into [the second noun].” instead;
if the noun is not a memory container:
say “That’s not something you can plug in to anything.” instead.

Unplugging it from is an action applying to two things. Understand “unplug [something] from [something]” as unplugging it from.

Check unplugging something from something:
unless the noun is connected:
say “[The noun] isn’t plugged in to anything.” instead;
otherwise:
unless the second noun is connected:
say “Nothing is plugged in to [the second noun].” instead.

Carry out unplugging something from something:
now the noun is not connected;
now the second noun is not connected.

Report unplugging:
say “You unplug [the noun] from [the second noun].”.

Report plugging: say “[one of]You shove [the noun] into [the second noun][or]You plug in [the noun].[cycling]”.

A computer is a device in the testarea.[/code]

In general you’re only making things harder on yourself by insisting on writing the implementation of the “Plugging it into” action as “Understand ‘plug [a memory container] into [a device]’ as plugging it into.” You’re much better off just saying “'Understand plug [something] into [something] as plugging it into” and then writing a check rule to disallow plugging anything but a memory container into anything, and disallowing plugging anything into something that isn’t a computer.

Hopefully that’s helpful; if not please keep asking and someone will get you on the right track.

I would define “plugged into” as a relation as Nitku suggested:

Device-connection relates one memory container to one device. The verb to be plugged into implies the device-connection relation.

With that in place, you can use phrases like “now the noun is plugged into the second noun” or “now the noun is not plugged into anything”. The game will remember which sticks are plugged into which computers, and you can use that in your check rules:

Check plugging it into: if the noun is plugged into something (called the current host): say "But [the noun] is already plugged into [the current host]." instead; if something (called the current stick) is plugged into the second noun: say "But [the current stick] is already plugged into [the second noun]." instead.

Thanks a lot, guys (and girls). Now my memory stick is working fine and I can get to the business of putting stuff on it.

I really am amazed by how friendly the people on this forum are, and how quick they respond! I got about three answers in 2 hours. On most forums, people get uppity and swear at you, and it isn’t particularly nice.

Also, is it okay if I rip your code completely, Endosphere? I copied and pasted it for now, but I will type it out manually if need be! :stuck_out_tongue:

@vapoware, that certainly looks a lot cleaner, and I may change it later, but for now I’m fed up with changing my memory stick code, so I think I’ll just stick with what I’ve got at the mo. Thanks anyway.

IntForum will definitely get a mention in my credits.

Again, thanks,

Pe-ads

Take it and use it any way you want, I’m glad I could help. Speaking only for myself, there’s never any need to give any credit for my answers to anything here on the forum.