How to iterate through a list of variables?

What I want to do is repeat through a list or table of truth states.

Then for each truth state, if it’s true, I want to repeat through a particular list of numbers that goes with that truth state.

How do you do something like this? I tried pairing the states with their lists in a table, but you can’t put variables in a table.



Why not just use the table cells themselves as your flag variables? If you post a larger example of what you’re trying to do I can provide more help.

I guess because it’s tedious to refer to / check table cells, and also more tedious for the author. This is for an extension, so I want to make the author-programmable parts of it as painless as possible.

OK, here’s more detail.

Below is a table that is illegal but shows what I’m after:

Table of cyoa-hardcoded key logic option (a truth state) the keys (a list) cyoa-allow quit cyoa-quit keys cyoa-allow undo cyoa-undo keys cyoa-support credits cyoa-credits keys cyoa-support transcripting cyoa-transcript keys cyoa-support saves cyoa-save keys
So I want to iterate through the rows.

If a truth state in the left column is true, I then want to iterate through the corresponding list of numbers in the right column.

Thanks much.


One roundabout way to do this is to use a text substitution. You can store the text variable “[if allow quit is true]X” in a table column or variable, then check whether it evaluates to “X” (if the variable is true) or the empty string (if false). Depending on your needs you can also look at the approach I took in my Boolean Variables extension (which basically provides an easy ‘options’ menu for turning things on and off during play).

You can’t store a variable reference in a table at compile time, but you can at run time. So one option would be to build the table at run time. Another would be to use list literals in the table.

Is this for handling key presses? Another option entirely would be to do it all programmatically. Have you seen Kerkerkruip’s approach? You pass in the keycode as the argument to a number based rulebook. Rules which match the keycodes run, and can process their own logic. If you want to make the options disable-able, it wouldn’t be hard to check in those rules whether they’re enabled or not, and if they aren’t make no decision.

Thanks for the ideas both.


Now that is interesting, I didn’t know that. How do you put a reference vs a value into a table at runtime?

I’m pretty sure that Inform would always put references into tables… you have to explicitly copy a value if you want that.

I don’t think I’m understanding. Here’s my test code.
Table of Temporary

X is initially 7.
Instead of jumping: increment X; say “Done.”.
Instead of waving hands:
say "X: [X] Val: ";
choose row 1 in the Table of Temporary;
say the val entry;
say line break;
now the val entry is X.
Test me with “wave / wave / jump / wave”.
Foo is a room.



It seems to copy X by value, not by reference.

Edit - Upon closer inspection of your example, I think what I say below doesn’t apply. But in case or FYI:

There’s been a change from Inform 6G60 to the new generation regarding the circumstances in which text substitutions fix their values, due to the fact that plain ol’ text and indexed text are now both just ‘text’.

It could be that you need to look into that change and the parameters around it to make the example work (you may need to set a preference or use a new particular phrase). Or it could be that Dannii’s recollection about how this can work is no longer true in the new Inform.


Ah, sorry, I wasn’t talking about simple values. Block values, tables and objects etc will be stored as references.