Managing Tables in Inform 7

Note: This first part is a bunch of background that may actually be pointless. The question is clearly marked at the end of this post. Also note that code snippets are just that. You need the framework from the example to run them.

I have been playing around with Example #323 Quiz Show in The Inform Recipe Book. My goal is to expand the game so that the player can review correct answers and the game stops asking if the answer is correct.

The second part was easier than the first:

Carry out guessing a topic : choose row with state of current state in the Table of Dates of Statehood; say "Correct! [comment entry] to be exact! blank out the whole row;
The first part didn’t go as well as I would have liked. You see, I had expanded the Table of Dates of Statehood to include more information, and I didn’t like blanking out the row. When the player guesses the correct answer, I had to store everything in a Table of Guessed Answers. Things get really confusing if the table has columns with the same name. So, this is what I did:

[code]
Carry out guessing a topic :
choose row with state of current state in the Table of Dates of Statehood;
say “Correct! [state entry] became a state on [comment entry] of that year.
It is the [admitted entry] state to be added to the Union.
Before that, it was [origin entry]. Good job!”;
let N be the substituted form of “[admitted entry]: [state entry] [comment entry], [year entry] from [origin entry]”;
blank out the whole row;
choose a blank row in the Table of Guessed Answers;
now the answer entry is N;

Table of Dates of Statehood
Admitted State Year Comment Origin
“1st” “Delaware” “1787” “December 7th” “The Colony of Delaware”
“2nd” “Pennsylvania” “1787” “December 12th” “The Proprietary Province of Pennsylvania”
“3rd” “New Jersey” “1787” “December 18th” “The Crown Colony of New Jersey”
“4th” “Georgia” “1788” “January 2nd” “The Crown Colony of Georgia”

Table of Guessed Answers
Answer(text)
with 50 blank rows[/code]
The problem with this approach is that it doesn’t allow flexibility. I only get one way to format the review. The system just runs out a list of rows in the Table of Guessed Answers. To get more flexibility, I get into tediously copying each Dates of Statehood column into a temporary variable and then copying it back out into the Guessed Answers table. Furthermore, if I want to do anything more with the Table of Dates of Statehood, I can’t. The information is lost.

I would love to add a column to the Dates of Statehood table (or keep an array of rows) that indicates whether or not the answer is guessed. But selecting filtered data from the table seems impossible.

So I guess here’s the Actual Question:
Is there some way of filtering table data like SQL so choose a random row in the Table of Dates of Statehood; could become something like: choose a random unguessed row in the Table of Dates of Statehood; [or maybe] choose a random row in the Table of Dates of Statehood where the guessed entry is false;
Hmm?

You could do this:

sort the Table of Dates of Statehood in random order;
choose a row with guessed of false in the Table of Dates of Statehood;

(“Choose a row” always picks the first row satisfying the condition, so you need to randomise the order first. If you need to return your table to its original order at any point, you can do that easily by sorting it on the “admitted” column.)

If a phrase “choose a random row in the TABLE where the COLUMN entry is VALUE” would be useful, it wouldn’t be too difficult to write an extension for it. (Linear time at best, of course, since it can’t modify the table or expect it to be sorted, but that shouldn’t really matter here.)

I think I’ll stick with jrb’s solution. Writing an extension is a bit beyond the scope of what I want to learn right now. I mean, it’s shiny and all, but I have to rein in the requirements, or I’ll never finish my objective.

Thanks for the help.