How to require the player to 'say' or 'type' certain words or phrases

The game I’m trying to make for a history project that requires the player to give a lot correct answers, deciphered codes and answering of riddles, etc. How can I require the player to give a specific answer?

So say if I have a door they can’t pass through until they answer the riddle:

The north door is a door. The north door is north of The Residence and south of the Ancient Slavery Exhibit.
The north door can be locked or unlocked.
The north door is closed.
The north door is locked.

The description of the north door is "There is a locked door here. But there’s a mechanical box where the doorknob ordinarily would be. The box seems to sense your presence and asks in a mechanical voice, 'What has man both in his self and items he removes from the wild, for which he places into his inventory?'."

The player would have to say ‘Property’ to have the door unlock.

One tip that’s broadly useful is that if you’re not sure how the Inform parser will interpret a command, you can type ACTIONS in the IDE and then try typing the command. If you try that here, you’ll see this:

>say property
(to yourself)
[answering yourself that "property"]
There is no reply.
[answering yourself that "property" - succeeded]

So Inform already understands commands of this type as the “answering someone that” action, which makes life easier (especially since it means you won’t get this action confused with the ubiquitous “say” command you’re using all the time in your code)! As you can probably guess, this action requires saying something to a person, and if no person is around, it will default to the player “answering” themself. You can run with this, but it’s a little awkward, so telling Inform that the player can use this command with doors might be helpful.

Here’s a simple little example that’s hopefully easy to generalize and make more robust (like giving a response if the player says something other than the right word, or changing the response if they say the password twice, etc…)

Understand "say [text] to [door]" as answering it that (with nouns reversed).

After answering the north door that "property":
	now the north door is unlocked;
	say "The mechanical box gives a short rumble, indicating that the door is now unlocked."
1 Like

Do you need to specifically say “property” to the door? I imagine that it would be easier to just say “property” to yourself, and the door overhears it, and unlock itself. Of course, I don’t know Inform7, so I may be wrong. But if the text is like that, then I expect to not have to type “… to door” for every guess.

1 Like

Yeah, the player can still just type “say property” – my tweak just means that if you do that, the parser will show “(to the north door)” rather than “(to yourself)” which I think seems more natural. This also makes coding the responses of various doors, objects, etc. a bit simpler, since you can tie the relevant code to the particular obstacle or mechanism, rather than having everything all tied to “answering yourself that X” – of course you can make things work either way, but in cases like say where the player is in a location with two different locked doors, this way is probably easier.

2 Likes

Thank you! That latter code worked perfectly!

What is the ‘understand’ function called? I.e. I want to learn more how it works for future interactions and want to read up on it in Documentation.

Chapter 17 in the Documentation is all about Understanding

In a nutshell ‘Understand … as …’ in a variety of forms allows you to tweak how Inform interprets commands, words and phrases that the player types.

2 Likes