How can I check the user's command?

+1 vote
83 views
asked Apr 23 in Authoring by Sciver (23 points)

I have a turn script that I need to be conditional depending on what the user's command entry is.
I still want to parse the command, but I want additional code to run depending on what the user just did...

As an arbitrary example, print a message admonishing the player for looking around idly when their life is in mortal danger this very moment.

Or actually in the specific case, not counting Look At [enemy] as a full turn, but counting any kid of physical action as a turn. Since looking at something doesn't necessarily take a long time, I don't want to end a player's combat turn when using Look At once. (repeated stares of course I'll punish later once I know how to differentiate)

I'd like to avoid passing everything through Get Input, as I've found it doesn't always work correctly. (Sometimes the text entered doesn't get processed and needs to be entered a second time. I experienced this frequently with the Character Naming script I made)

so can anyone help?

1 Answer

+1 vote
answered Apr 23 by Sciver (23 points)

Ok, so, after some testing, it looks like you can get this information by looking at this variable:

game.pov.currentcommandpattern.name

which is the name of the last valid command OR verb used. To compare a command, that command must have a name attribute. (all the default game commands and verbs do, but custom ones need to be assigned a name upon creation.)

When used in a turn script at the start of the game, it will not exist. Turn scripts appear to execute BEFORE the player finishes their turn, that is, at the beginning of a turn, not the end. Something I'll have to keep in mind.

This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...