Iterating through a table and matching a custom action against text

Yeah, two of Inform’s largest and most gratuitous misleads are that the topic understood is a snippet variable and that topic in an action specification needs to correspond to the grammar token text.

And topics are woefully underdocumented.

1 Like

Which is also why “the topic understood” can be printed but a topic cannot! Because it’s actually a snippet.

The clarifications are much appreciated! I’ll give these suggestions a go and see what makes sense. A fatal flaw of the “copy whatever seems to work and pretend to understand it while working with it” is not, in fact, understanding its fundamental structure.

The exact solution i was looking for proved to be this. I was fiddling with this bit since i’m adding the table functionality in the paper, only to realise that “topic” is not explicitly mentioned nor necessitated anywhere. just as @StJohnLimbo mentioned. Here’s the full functioning bit:

Prayingtox is an action applying to one topic.

Understand "pray to [text]" as prayingtox.

Carry out prayingtox:
	  if the topic understood is a god listed in the Table of Prayerlines:
		say "You take a moment to recall your mother's teachings. [line break]
[line entry]";
	otherwise:
		say "You don't remember a prayer for that divinity."
		
Understand "pray" as a mistake ("You murmur a small prayer to a minor divinity"). 


Table of Prayerlines
god(topic)	line
"Zeus"	"'Zeus, mighty ruler of the sky, grant me the strength to face the trials that lie ahead.'"
...

Which successfully understands Zeus in a case insensitive fashion.

1 Like