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.
4 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