Getting the command that led to the action

The hypothetical scenario is this: I have a PC that can perform many different kinds of dances: waltz, samba, twist, etc. Instead of making a bunch of new dance actions to correspond to each type of dance, I want to create one dancing action that changes its carry out and report rules based on the specific, one-word command that the player entered. I could do this if I could see the one-word command the player entered but I don’t know how to grab that in the dancing action code.

My questions are:

(1) Is the proposed solution above the best way to do this or is there a better way or should I just implement each individual dance action?

(2) If the proposed solution is viable, how do I get the one-word command from within the action code?

Appreciate any ideas and suggestions.

See §18.33. Reading a command
http://inform7.com/book/WI_18_33.html

Specifically it has an example:

After reading a command:
    if the player's command includes "please":
        say "Please do not say please.";
        reject the player's command.

With that template, you could check if the player's command includes "waltz": then redirect it to your dancing action. “Dancing” is not a pre-defined action that is blocked by default - so you could create it.

1 Like

You could continue to have a single dance action while also giving the parser a stock of dance types to understand (without having to deal with “After reading a command” yourself). You can then get the “dance type” requested by querying for “the dance-type understood”.

"The Ball" by ArdiMaster

A dance-type is a kind of value. The dance-types are waltz, samba, and twist.

Dancing is an action applying to one dance-type.
Understand "dance the/a/-- [dance-type]" as dancing.
Understand "[dance-type]" as dancing.
To dance is a verb.

Report an actor dancing:
	say "[The actor] [dance] [the dance-type understood]."

Ballroom is a room.

When compiled, the above understands the defined dance types, both with and without a leading “dance” command:

>dance the waltz
You dance waltz.

>dance waltz
You dance waltz.

>samba
You dance samba.
5 Likes

I gave an attempt at coding an example for this. Your mileage may vary :slightly_smiling_face:. The approach uses a topic to capture any random text input that may represent a dance and two actions are created, one for dancing as an individual and one for a partner. Hope it can help!

Ballroom is a room.  Alison is a person.  Alison is in the ballroom.

Individual_dancing is an action applying to one topic.  Understand "dance [text]" or "dance the [text]" or "perform [text]" or "execute the [text]" or "boogie the [text]" or "get down with the [text]" or "cut a rug doing the [text]" as Individual_dancing.

Instead of individual_dancing:
	say "You dance the [the topic understood] in freakishly amazing style and grace.";

Partner_dancing is an action applying to one topic and one thing.  Understand "dance the [text] with [someone]" or "[text] with [someone]" or "boogie the [text] with [someone]" or "get down doing the [text] with [someone] " or "cut the rug doing the [text] with [someone]" or "perform the [text] with [someone]" as Partner_dancing.

Instead of partner_dancing:
	say "You dance the [the topic understood] with [the second noun] and the crowd goes wild!".

Here is what the game play looks like when running the code:

Ballroom
You can see Alison here.

>boogie the bunny hop
You dance the bunny hop in freakishly amazing style and grace.

>get down with the safety dance
You dance the safety dance in freakishly amazing style and grace.

>execute the macarena
You dance the macarena in freakishly amazing style and grace.

>dance the jig
You dance the jig in freakishly amazing style and grace.

>boogie the waltz with Alison
You dance the waltz with Alison and the crowd goes wild!

>head bang with Alison
You dance the head bang with Alison and the crowd goes wild!

>lonely dance with myself
You dance the lonely dance with yourself and the crowd goes wild!
1 Like

Here is yet another way to do things:

A dance-type is a kind of value. The dance-types are waltz, samba, and twist.

Dancing is an action applying to one dance-type.
To dance is a verb.

Report an actor dancing:
	say "[The actor] [dance] [the dance-type understood]."

Waltzing is an action applying to nothing. Understand "waltz" as waltzing.
Carry out waltzing: instead try dancing the waltz.

Sambaing is an action applying to nothing. Understand "samba" as sambaing.
Carry out sambaing: instead try dancing the samba.

Twisting is an action applying to nothing. Understand "twist" as twisting.
Carry out twisting: instead try dancing the twist.

This is similar to Adrian’s version except that the dancing action is purely internal. The player cannot invoke dancing directly. Instead, they type one of the available actions (waltzing, sambaing, twisting) and that redirects to the dancing action.

2 Likes

Lots of great suggestions here, so thanks for each one :smile:.

I can only pick one solution, wish I could pick four. Adrian’s solution is the easiest for me to understand as an Inform 7 noob, so I am going to try that one.

I can show you something fun I used myself recently. :slight_smile: (It’s perhaps not quite suited for dance moves as is, but the extension by itself might be of use.)

Include Snippetage by Dave Robinson.

To try is a verb.  To cut is a verb.  To slice is a verb.  To prune is a verb.  To chop is a verb.

Table of Verb Translation
topic	verb
"cut"	verb cut
"slice"	verb slice
"prune"	verb prune
"chop"	verb chop

To decide which verb is the current verb:
	let v be the verb word;
	repeat through Table of Verb Translation:
		if v matches topic entry:
			decide on verb entry;
	decide on verb pass.

Check cutting something:
    if the noun is the player:
        say "Trying to [infinitive of current verb] [ourselves] would be silly." instead;
    otherwise if the noun is a person:
        say "Trying to [infinitive of current verb] [regarding the noun][those] would be unwise." instead;
    otherwise:
        say "[We] [try] [present participle of the current verb] [the noun], but it is futile." instead;

With this setup, [current verb] is an adaptive verb that you can do fun things with like the above (eg. it can automatically translate “cut” into “cutting”). But that only works for verbs in the Table of Verb Translation, so you need to add a row for anything Understood as a command that ends up using it.

For a more basic setup (using only the include of Snippetage without any of the rest of the code) you can use [verb word] to get the exact verb they typed.

1 Like

Years after I used this very solution to solve my game problem (thank you for the help), I realize that I still don’t understand why a piece of this code works correctly. So, I thought I would follow up with more Inform knowledge under my belt and see if I can get some help to understand it now.

I see that Dancing is an action applying to one dance-type. I envision this as a dancing action that also expects a dance-type argument. The dance-type argument is accessed via [the dance-type understood].

This all makes sense to me for a command like dance waltz. The “dance” part tells you to use the dancing action and the “waltz” part tells you the dance-type understood.

But what is Inform doing when the player command is waltz?

Understand "[dance-type]" as dancing. tells Inform to use the dancing action, but why doesn’t the line Dancing is an action applying to one dance-type. cause a compilation error? The command is only one word, so wouldn’t that only match Dancing is an action applying to nothing.? It’s almost like the single word is acting like both the reference to the action and also as the value understood at the same time.

Anyway, again, thanks for the original solution. It worked beautifully. How does that specific piece work?

It is, but only because you declared that to be legal with “Understand “[dance-type]” as dancing.” In other words, you’ve allowed for a grammar that consists of only the needed value (which you’ve already declared as a dance-type).

Actions applying to nothing have no noun/value understood. (Like “waiting.”)

When you declare “dancing” to apply to “one dance-type”, that’s the only parameter that needs to be specified in its Understand lines. The lines can be as short as “[dance-type]” or as long as “foo bar baz blah blah dance [dance-type] etc etc etc etc etc” (or longer, I think the limit is 32 words), as long as they contain [dance-type] somewhere.

The point of the grammar line is to do two things. One, it needs to decide which action is being performed. And two, it needs to supply all the parameters for that action. Since no other action uses simply “waltz” (or “[dance-type]”) on its own, the first part isn’t an issue. And since you’re providing one dance-type, the second part also isn’t an issue: that’s the only parameter this action needs.