Iterating through a table and matching a custom action against text

Getting around to finalising the paper for my thesis, which naturally means i’m instead procrastinating by adding polish on my game, instead of writing down documentation and doing “work”.

Now, i vaguely understand the ability to iterate through a table in inform, as well as the declaration of new actions. What i don’t see how to merge, is creating a new action, namely praying, and then iterating through the table of divinities and finally delivering the prayer line.

Prayingtox is an action applying to one thing.

Understand "pray to [something]" as prayingtox.

Carry out prayingtox:
	  if the topic understood is a topic 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"). 

Now the table of prayerlines is the typical, Table Decleration, Subject, response, with subject being “god” and response being “line”.

This is most likely included somewhere, but i can’t fathom where since i closed all of my working tabs as soon as i hit the deadline for the springthing… Which naturally, i came to regret a short month later.

1 Like

What part of your example is not working?

Comparing a topic to a text in a table is annoying. I usually choose to declare things in this kind of situation so the parser can do the matching. So

A god is a kind of thing.
Vishnu is a god.
Jehovah is a god.

Then

Understand "pray to [any god]" as prayingtox.

Edited to add:
or better:

Understand "pray to [anything]" as prayingtox.
Check praying to something that is not a god:
    say "[The noun] won't answer your prayers." instead;
1 Like

Pray to zeus for example gives the error of the [something] as not being visible. Which makes me realise that i didn’t actually declare the “god” parts… which yes i see would be problematic.

i’d prefer not to declare them as actual people, so the fundamental question is linking the [something] as the iteration of the names of the divinities through the table. Do i just declare them as things of a particular quality?

Comparing a topic to anything else is nearly impossible!

EDIT: Unless you meant comparing a topic to a text, as opposed to a topic in a table… but this is a digression. I suspect the example you gave with “pray to [any god]” is the solution GJMen is looking for.

2 Likes

Added the A god is a kind of thing bit and changed something to anything.

so now we have the

Table of Prayerlines
god line

with gods existing.
Pray to zeus, however give the “That noun did not make sense in this context.” error which implies the understanding of the god listed as “Zeus” in the table, but that it does not give the line. (i think.)

I’ve graduated to the not understanding what i’m not understanding bit, so there’s progress. Is it inherently bad practice to check the topic to the text of the god?

Or i did something silly in the declarations, since my gods are declared as texts, ie “Zeus”, “Hera” e.t.c in the table?

Can you post a full example? I’ve lost the thread.

Right sorry, i forgot that i don’t need to keep being vague due to competition and assignment considerations.

Prayingtox is an action applying to one thing.

Understand "pray to [anything]" as prayingtox.

Carry out prayingtox:
	  if the topic understood is a topic 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."
		

A god is a kind of thing.


Understand "pray" as a mistake ("You murmur a small prayer to a minor divinity"). 


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

The general idea is to recognise the player’s attempt to pray to a particular god in the dodekatheon as opposed to simply praying, checking whether the noun given is within the table of divinities and then delivering the line.

This is all working under the assumption that the god bit in the table of prayerlines is recognised as the thing declared above.

You’ll get the “noun did not make sense in that context” error unless you change the first two lines to

Prayingtox is an action applying to one topic.

Understand "pray to [text]" as prayingtox.

Then you have to figure out how to get the text matching to work, which took me a while, but I got:

Prayingtox is an action applying to one topic.

Understand "pray to [text]" as prayingtox.

Carry out prayingtox:
	repeat through table of prayerlines:
		if topic understood matches god entry:
			say "[line entry][line break]";
			continue the action;
	say "You don't remember a prayer for that divinity."
		

A god is a kind of thing.


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.'"

Lab is a room.

But this is fragile since it is case-sensitive, it doesn’t handle possible articles, you can’t have synonyms/different spellings, etc. I’d still recommend to use the method I mentioned above. No reason to make the gods people, just things.

2 Likes

Realization of a fundamental lack of understanding: What exactly is a “topic” in the reference? Is it the god-line tuple?

As for case sensitivity i was going to deal with it using a regex, and then match it onto the table text…

Which seems to be a lot of work for what i could also declare as individual things in a list or something, with each having a name quality… Maybe i ought to start looking at everything from the ground up and start fixing some “good enough” solutions.

One thing you might find useful is: Defining Things With Tables

Then you just need:

Carry out prayingtox:
    say "[prayer][line break]";

where “prayer” is whatever you want to call the column that holds the text of the prayer.

1 Like

Might be a good job for a kind of value.

Lab is a room.
a divinity is a kind of value. the divinities are defined by the table of prayer.

Table of Prayer
divinity    prayer-response
Zeus    "I dunno, try disguising yourself as a swan."
ares    "Violence is probably the answer to this one."

praying is an action applying to one divinity.
understand "pray to [divinity]" as praying.

carry out praying:
    choose the row with divinity of divinity understood in table of prayer;
    say the prayer-response entry.
3 Likes

The reason I don’t like this approach is because praying to non-gods results in “I didn’t understand that sentence.” rather than some other more sensible feedback. I’d add a few lines:

praying wrongly is an action applying to one thing.
understand "pray to [any thing]" as praying wrongly.

The ball is in the lab.

check praying wrongly:
	say "That won't hear your prayers." instead;
1 Like

or…

understand "pray to [text]" as a mistake ("There is no response.")
1 Like

Yeah that’s a good approach. I always forget about understand as a mistake.

1 Like

Comparing a “snippet” (the topic understood) to a topic in a table should work fine, and isn’t case sensitive, AFAIK (unlike when matching text variables to each other). “ZEUS” and “zeus” work just as well as “Zeus” in the example.

I’m not saying this is necessarily better than other approaches, but I think it’s quite workable.

As 16.13. Topic columns notes, “Topics can use the full range of abilities of the ‘understanding’ system”.

So, we can also take care of synonyms and articles directly within the table (or with additional understand lines outside of it):

Table of Prayerlines
god (topic)	line
"Zeus/Jupiter" or "the/-- thunderer"	"'Zeus, mighty ruler of the sky, grant me the strength to face the trials that lie ahead.'"
"[Artemis]"	"Prayer text for Artemis here."

Understand "Artemis/Diana" or "the/-- huntress" as "[Artemis]".

This will recognize “ZEUS”, “jupiter”, “thunderer”, “the Thunderer” etc. in the input.

The comparison of the snippet to the table topic can be done as it is in your code, or alternatively like this:

Carry out prayingtox:
	if the topic understood is a god listed in the table of prayerlines:
		say "[line entry][line break]";
	otherwise:
		say "You don't remember a prayer for that divinity."

Edited to add: Maybe it’s also helpful (for others reading the thread later) to mention that the god part in “if the topic understood is a god listed in the table [...]” just refers to the name of the column; it doesn’t have anything to do with the line from the example code “A god is a kind of thing.”, which we can delete.

And we need to mention the column name; writing “if the topic understood is a topic listed in the table [...]” (as it was in the OP’s code) wouldn’t yield the desired results (unless of course we just call the column “topic”, then it would work).

4 Likes

All this is good to know. I’ve always struggled with the meanings of snippet/topic/text.

1 Like

Me too, it can be quite confusing.

I also recommend calling your action “praying to” instead of “prayingtox”, because then you can write rules like:

Instead of praying to "Zeus" or "Jupiter":

Imo this is much more readable than:

Instead of prayingtox "Zeus" or "Jupiter":

You can also check conditions like whether “we have prayed”.

2 Likes

Yes, Inform doesn’t do a great job of distinguishing these. A snippet is a pointer into the player’s command (giving a starting point and a length), a topic is like an Understand line, and a text is either a string of characters or a routine that prints something to the screen. And when the differences between these become important it quickly becomes confusing.

1 Like