Inform 7 coding question

Hello folks,

Just something I’ve been playing with is this handy table to catch more esoteric topics brought up throughout the game:

Thinking abstractly about is an action applying to one topic. Understand "who is [text]" or "who's [text]" or "whos [text]" or "who am [text]" or "think about [text]" or "ponder [text]" or "remember [text]" or "think about [text]" or "recall [text]" or "what's [text]" or "whats [text]" or "what is [text]" or "what are [text]" or "what're [text]" or "why [text]" or "why is [text]" or "why are [text]" or "contemplate [text]" or "dream about [text]" or "miss [text]" as thinking abstractly about.

Thinking concretely about is an action applying to one thing. Understand "who is [something]" or "who's [something]" or "whos [something]" or "who am [something]" or "think about [something]" or "ponder [something]" or "remember [something]" or "think about [something]" or "recall [something]" or "what's [something]" or "whats [something]" or "what is [something]" or "what are [something]" or "what're [something]" or "why [something]" or "why is [something]" or "why are [something]" or "contemplate [something]" or "dream about [something]" or "miss [something]" or "[something]" as thinking concretely about.

Carry out thinking abstractly about: say "Not relevant. Move on."

Instead of thinking abstractly about a topic listed in the Table of Concepts:
	say "[reply entry][paragraph break]";

Table of Concepts
topic				reply
"Potato"			"[one of]Yum, Spuds.[or]Yep, spuds.[stopping]"
"Onion"				"Nope. No breath mints."
"Antacid"			"Should have eaten fewer potatoes."
"Dirty dishes"		"Not a tonight problem."
"Kitchen"			"Mysterious originator of tasty food."
"Bed"				"Your next stop."

Basically, if you ask about something not in the table, you’re met with a redirect response. If you ask about something in the table, you get the preloaded response. Pretty straight forward.

I even have it so if you simply enter the actual item in the table with no other words, it’ll still trigger the response.

My question is how to make the word in the table take precedence over any other words included. Like, if I type “>incinerate potato” I’d hope to still get “Yum, Spuds.” as a response even though I didn’t anticipate the accompanying word(s).

Think of it as a keyword redirect; if a player uses one of the keywords in the table anywhere in any prompt, it’ll disregard the other accompanying words and simply default to the table response.

Is it as simple as some form of swapping out the understand line for “thinking concretely” to something like this?:

Understand "[something]" or "[text] [something]" or "[something] [text]" or "[text] [something] [text]" as thinking concretely about.

Because if it is, my code doesn’t work for that. Not sure if I’m barking up the right tree or forcing a square peg into a round hole.

1 Like

I think what you want is something like this:

Instead of thinking abstractly about a topic listed in the Table of Concepts:
	if the topic understood includes topic entry:
		say "[reply entry][paragraph break]".

Does that work?

1 Like

Like, I know I could do something like:

After reading a command:
	if the player's command includes "potato":
		say "[one of]Yum, Spuds.[or]Yep, spuds.[stopping]" instead.

…separately for each keyword, but I was hoping for something more elegant and less repetitious like a table.

It compiles, but it doesn’t get the desired result.

>stupid pototo

Should trigger the table response, but no dice.

Thank you for trying to help, by the way.

Does this work?

After reading a command:
	Repeat through Table of Concepts:
		If the player's command matches topic entry, say "[reply entry][paragraph break]" instead.

You might need to manually tell Inform to follow the turn sequence rules or other housekeeping stuff like that since the “instead” is terminating the action early-- IIRC the after reading a command stuff can get a little funky, but I’m not 100% sure how it works!

EDIT: If I were to editorialize, I might add that I personally probably wouldn’t add this unless thinking about stuff was a major, major part of your game. I’m the kind of player who often mistypes actions, or mistakes a rhetorical question for a disambiguation prompt, and it’d be confusing to me to see that input reinterpreted – I’d rather the game just tell me “you can think about stuff by typing THINK ABOUT STUFF” and then know exactly what I’m supposed to do, again unless there’d be so much repetition than I’d be chafing at having to type the THINK ABOUT over and over. Even then, making the command “T [something]” might be a better solution IMO.

1 Like

Almost, but not quite. After some tinkering, I got it to work as follows:

After reading a command:
	Repeat through Table of Concepts:
		If the player's command includes topic entry, say "[reply entry][paragraph break]" instead.

Thank you very much for helping me figure that out.

As for the use case, it isn’t really about “thinking” about stuff. I have something entirely different in mind and I’m not sure if it’ll even work out, but I’d need something like this to even attempt it. Agreed that having the game assume you’re thinking about rocks because you typed “>thow rock” instead of “>throw rock” would get old very fast.

1 Like

This variant would let it be a regular action with the rest of the turn sequence occurring as usual.

After reading a command:
repeat through Table of Concepts begin;
  if the player's command matches topic entry begin;
    change the text of the player's command to "think about [the player's command]";
    break;
  end if;
end repeat;
2 Likes

Ah, I was trying to do something like that, except I kept putting in stuff like “[the topic understood]” or “[the substituted form of the topic understood]” and it wasn’t working!

(See, this is what I meant in that PM I sent you a bit ago about how when I answer one of these topics, it’s at best 75% as good as when you weigh in!)

1 Like

Oh hey, time for this extension to be useful!

This is exactly what Parser Overrides are meant for. If you put your response in an “after reading a command” rule, then you’re bypassing Inform’s whole action machinery and making it difficult to tweak the responses in different circumstances, but if you rewrite the command, then you can end up with odd bugs like “GO WEST. INCINERATE POTATO” turning into “THINK ABOUT GO WEST. INCINERATE POTATO”.

A parser override rule:
    repeat through the Table of Concepts:
        if the player's command includes the topic entry:
            override thinking about overridden topic "[the matched text]".

Now any command including “potato” will be parsed into the action “thinking about ‘potato’”.

3 Likes

The sick thing is that I’ve already read this and liked it… and then promptly and utterly forgot about it. My, how embarrassing. :face_with_open_eyes_and_hand_over_mouth:

3 Likes