Pulling and printing specific rows in a table

I’m struggling to interpret the manual’s chapter on tables for what is likely a very easy task; I’m not understanding the syntax.

I want to pull and print rows for a table, but only rows with a specific entry. In my case, the rows with the “StoryRevealed” of “Yes”. My incorrect, example code below.

StoryNum is a number which varies. StoryNum is usually 1.

Understand "Recall Story" as recalling story. Recalling story is an action applying to nothing.

Instead of recalling story:
	if StoryNum is greater than 1:
		repeat through the Table of Story History:
			choose row with a StoryRevealed of "Yes" in the Table of Story History;
			say "[line break][response entry]";
	otherwise:
		say "You need to investigate more.".

Table of Story History
StoryRevealed	Step	Response
"Yes"	1	"Story bit 1"
"Yes"	2	"Story bit 2"
"No"	3	"Story bit 3"
"No"	4	"Story bit 4"
"No"	5	"Story bit 5"
"No"	6	"Story bit 6"
"No"	7	"Story bit 7"
"No"	8	"Story bit 8"
"No"	9	"Story bit 9"
"No"	10	"Story bit 10"
"No"	11	"Story bit 11"
"No"	12	"Story bit 12"
"No"	13	"Story bit 13"
"No"	14	"Story bit 14"

(“StoryNum” gets incremented by a different verb along the way.) That code is grabbing the first row and printing it 14 times. Again, I just want to print the rows that have the “StoryRevealed” of “Yes”, which in this instance is just the first two rows.

The problem is that ‘choose row…’ searches the entire table each iteration of the repeat (14 times) for the first row with a StoryRevealed of “Yes”.

You want:

Instead of recalling story:
	if StoryNum is greater than 1:
		repeat through the Table of Story History:
			if StoryRevealed entry exactly matches the text "Yes":
				say "[line break][response entry]";
	otherwise:
		say "You need to investigate more.".
1 Like

You’ll get very slightly better performance (not that it matters in a table that small, but presumably you’ll be adding more things) if you use a truth state rather than a string:

  • Change your "Yes" and "No" in the table to true and false (without quotes).
  • Change the if statement to:
    if StoryRevealed entry is true:
    

Also, FWIW, you can simplify the declaration of StoryNum a bit. This is sufficient:

StoryNum is initially 1.
1 Like

Thank you both!