Action names

I’m always getting into trouble mixing and matching kinds of values (eg text vs snippets; this time stored actions vs action-names) and bumbling around trying to find a way to make what I want to do work.

What I want to do this time is: the player is wearing various restraints and has to get them off; while wearing them, however, various restraints prevent various actions. Originally I was bundling the actions together as behaviours, but it was all complicated, and it seemed like it’d be more elegant to do something like:

[code]A restraint is a kind of thing. A restraint is usually wearable. The blindfold, the gag, the collar, the handcuffs, and the shackles are restraints which are worn.

Instead of doing something when the player wears a restraint:
repeat through the Table of Restricted Movements:
if the current action is the movement entry:
say “You have no hope of [the current action] while wearing [the restraint entry with definite articles].”

Table of Restricted Movements
movement restraint
going {collar, shackles}
eating {gag, handcuffs}
jumping {collar, shackles}[/code]

Various fine-tuning is necessary to add in a condition that the player actually be wearing the specific restraints that restrict the specific movement but it’s presently moot because:

The problem is that of course, while this works fine for “jumping” which doesn’t take a noun, it doesn’t recognise “going” or “eating” because the current action will be eg “going north” or “eating gag”. So I tried if the action-name part of the current action is the movement entry and got

Personally I’m all for miscegenation in kinds of value, but since it’s not to be - is there any way of doing what I want to do with a table, or shall I go back to my clunky behaviours?

Oh never mind! I went to do the dishes and solved it: if the action-name part of the current action is the action-name part of the movement entry:
The moral of the story is, always leave your dishes unwashed in case you get stuck on a coding problem and need something boring to think over. :smiley:

I’d be curious to see how you’ve developed this example. I’m having trouble with it, primarily because I don’t know the syntax for extracting a list entry from a table entry. Here’s what I’ve tried:

[code]A restraint is a kind of thing. A restraint is usually wearable. The blindfold, the gag, the collar, some handcuffs, and some shackles are restraints.

Instead of doing something when the player wears a restraint:
repeat through the Table of Restricted Movements:
if the action-name part of the current action is the action-name part of the movement entry:
say “You have no hope of [the current action] while wearing [the restraint entry with definite articles].”;
otherwise:
continue the action.

The Dungeon is a room. “A dank and dismal dungeon. You can go north.”

A German chocoloate cake is in the Dungeon. The cake is edible. The description is “Mmm – that cake sure does look good!”

The Crypt is north of the Dungeon.

The player wears the collar and the handcuffs.

Table of Restricted Movements
movement restraint
going {collar, shackles}
eating {gag, handcuffs}
jumping {collar, shackles}[/code]But the results are less than spectacular. The player can jump or eat the cake without problems. Going north will print out the error message from the Instead rule … but then the action will take place anyhow.

Ideally, I’d like to see the error message refer to one specific restraint, not to a list of them. And of course the Instead rule needs to test whether the player is actually wearing the restraint in question. Currently it doesn’t do that.

I’d love to include this in an Appendix in the upcoming expanded edition of the Inform 7 Handbook … but at the moment I don’t see how to get it working. Is it working for you? If so, are you willing to share your secrets?

–JA

I did manage to get it working. Let’s see…

To stop the going north from succeeding despite the error message printing, we need another ‘instead’: say "You have no hope of [the current action] while wearing [the restraint entry with definite articles]." instead; “Stop the action” would work too; I don’t know what best practice is.

And the reason it lets you do anything other than going was that the “otherwise” clause was inside the repeat loop, so it only tested the first row of the table before effectively breaking the loop.

The remaining problem is that in the code I posted I hadn’t got around to actually testing whether or not the player is actually wearing the restraints that prevent the action; once that’s added in, the full “Instead” rule is:

Instead of doing something when the player wears a restraint: repeat through the Table of Restricted Movements: if the action-name part of the current action is the action-name part of the movement entry: let problems be the list of restraints worn by the player; repeat with the item running through the list of restraints worn by the player: if the item is not listed in the restraint entry, remove the item from problems; if problems is not empty, say "You have no hope of [the current action] while wearing [problems with definite articles]." instead; continue the action.Now when you’re wearing the collar and handcuffs and try to go north it only complains about the collar; and when you take off the collar it lets you go where you like.

(Btw, I’m using lists of restraints rather than a specific restraint because if, eg, something is tying you to the wall and something else is shackling your legs, then both those things will prevent you going north, and it would seem misleading to refer to only one in the problem message. A simpler puzzle mightn’t require all that though.)

(The only remaining problem I have is that when I try to list all the actions in the Inform dictionary into my table, it gives me a giant compile error of death:

I’ve fixed this for now by trimming the table down to just the actions that are relevant to my story, but I may tear my hair out when I need to create new actions later on and the table gets too long again.)

Very cool – thanks. This is now one of half a dozen examples in an Appendix at the end of the Handbook.

One way to avoid the compiler error might be to reverse the table. Instead of using a line for every action name, use a line for every restraint, and then make a list of action names in a second column. I may play around with that a little. It would mean restructuring the Instead rule, but maybe there’s a way to do it.

–JA

Okay, with a little help from Mike Tarbert, I managed to work this out. I reversed the table so that the actions are in a list, and then reversed the Instead rule. Here’s a complete short game that tests it. The handcuffs required a bit of handholding (if you see what I mean), because Inform stupidly won’t let something be lockable unless it’s a door or a container.

[code]A restraint is a kind of thing. A restraint is usually wearable. The blindfold, the gag, the ball-and-chain, and some handcuffs are restraints.

Instead of doing something when the player wears a restraint:
repeat through the Table of Restricted Movements:
if the player wears the restraint entry:
let impulses be a list of action-names;
let impulses be the movement entry;
if the action-name part of the current action is listed in impulses:
say “You have no hope of [the current action] while wearing [the restraint entry].” instead;
continue the action.

The handcuffs can be locked or unlocked. The handcuffs are locked. The small iron key unlocks the handcuffs.

Instead of locking the handcuffs with the small iron key:
if the handcuffs are locked:
say “They’re already locked.”;
otherwise if the player does not carry the small iron key:
say “You don’t seem to have the key.”;
otherwise:
now the handcuffs are locked;
say “You lock the handcuffs with the small iron key.”

Instead of taking off the handcuffs:
if the handcuffs are locked:
say “The handcuffs seem to be locked.”;
otherwise:
now the player carries the handcuffs;
say “You remove the handcuffs.”

Instead of wearing the handcuffs:
if the handcuffs are worn:
say “You’re already wearing the handcuffs.”;
otherwise if the handcuffs are locked:
say “You’ll need to unlock the handcuffs before you can put them on.”;
otherwise:
now the player wears the handcuffs;
say “You put on the handcuffs.”

Instead of unlocking the handcuffs with the small iron key:
if the handcuffs are unlocked:
say “But they’re not locked!”;
otherwise if the player does not carry the small iron key:
say “You don’t seem to have the key.”;
otherwise:
now the handcuffs are unlocked;
say “It’s awkward, but you manage to insert the key in the keyhole and turn it. Now the handcuffs are unlocked.”

Instead of taking the small iron key when the player wears the handcuffs:
now the player carries the small iron key;
say “You manage to pick up the key, even though you’re wearing handcuffs.”

The Dungeon is a room. “A dank and dismal dungeon. You can go north.”

The Dismal Crypt is north of the Dungeon. “The walls of the crypt are oozing…”

The player wears the ball-and-chain and the handcuffs.

The tool chest is an openable container in the Dungeon. The tool chest is closed. The blindfold and gag are in the tool chest. The small iron key is in the tool chest.

Dave is a man in the Dungeon.

Table of Restricted Movements
restraint movement
ball-and-chain {going action, jumping action, entering action, exiting action, getting off action, climbing action}
gag {eating action, kissing action, answering it that action, telling it about action, asking it about action, asking it for action, saying yes action, saying no action, tasting action, saying sorry action, singing action}
handcuffs {taking action, removing it from action, taking off action, dropping action, putting it on action, inserting it into action, searching action, touching action, waving action, pulling action, pushing action, turning action, squeezing action, eating action, consulting it about action, locking it with action, unlocking it with action, switching on action, switching off action, closing action, wearing action, attacking action, showing it to action, throwing it at action, cutting action, tying it to action, drinking action, swinging action, rubbing action, setting it to action}
blindfold {looking action, searching action, examining action}

Test me with “n / remove ball-and-chain / remove handcuffs / open chest / unlock handcuffs with key / remove handcuffs / remove ball-and-chain / n”.[/code]
You’ll note that the opening action is specifically not included in the list of actions in the table that corresponds to the handcuffs. Opening the chest could, instead, be handled specifically. Feel free to play around with this and let me know if there are problems with it!

–JA

I know this must be a bit of a bump… but why are you trying to work this out?
Even so - its kinky :wink: