Cross Referencing Tables

I am trying to reference a table from inside another table. The code below is incorrect and incomplete, but should get across what I am trying to do.

Table of Example 1
number	table
1	Table of Example 2

Table of Example 2
rule	        number
example rule	1

When play begins:
	repeat through Table of Example 1:
		repeat through the table entry:
			follow the rule entry for the number entry;

Is this doable?

You can store table-names within tables, so the answer would be yes.

As a quick example:

[code]“Testing”

Table of Answer Options
T_Name
Table of Blunt Answers

Table of Blunt Answers
Answer
“Yeah!”

When play begins:
choose row 1 in Table of Answer Options;
choose row 1 in T_Name Entry;
say Answer Entry.

Lab is a room.[/code]

I imagine your repeat blocks will cause problems, if so make a new phrase applying to a table name and put your second repeat block in there.

So the problem is not that a table can’t store a table name, but that a table name stored in a table can’t be used in a repeat phrase? If that’s right, I’m in trouble on this endeavor because the entire idea is that in he final version of this (if there ever is one) I’d need to use a repeat phrase, not a choose, because there would be multiple rows that need to be selected programmatically by repeating through them to find the correct one to use in a circumstance.

Is that doable?

Nevermind… this seems to work fine, but for some reason it was giving me an error on the repeat phrase indeed before, and I don’t know what I had different. It works now without issue, probably just some weird missed syntax or something in my real code that I entered and then fixed without noticing. If it happens again, I’ll post a more complete example…

No, that’s fine.

What was the error with your original code? As far as I can tell the table was fine, the repeat statements were fine, and the compiler was only complaining about the “follow” line.

I’m actually not certain what was happening before, but this is very related… I’m trying to pass a rule entry from one part of the table processing logic to the other, and getting an issue there now. Again, the rule itself is incomplete nonsense right now, just for example, but I’m getting an error with this that it doesn’t seem like it can understand the follow rule again. (please excuse the table formatting being wonky in the forum).

Adding is a number based rulebook.

Adding a number (called it) (this is the add a number rule):
	say "[it]";

Table of Example 1
rule	number	t-name
add a number rule	1	Table of Example 2

Table of Example 2
number
1

When play begins:
	repeat through Table of Example 1:
		let x be the rule entry;
		repeat through the t-name entry:
			follow x for the number entry;

The compiler seems to be unable to work out the exact type of the rule column – even if you give it explicitly:

Table of Example 2
rule (number based rule)	number
add a number rule	1

You can work around this by fooling I7’s type system. Of course this will break horribly if you put a rule in the table which isn’t number-based.

The Kitchen is a room.

Adding is a number based rulebook.

Adding a number (called X) (this is the add a number rule):
	say "Rule got [X].";

Adding a number (called X) (this is the other-add a number rule):
	say "Other rule got [X].";

Table of Example 1
number	table
1	Table of Example 2

Table of Example 2
rule (number based rule)	number
add a number rule	1
other-add a number rule	2

To decide what number based rule is forcibly cast (R - rule): (- {R} -).

When play begins:
	showme the contents of Table of Example 2;
	repeat through Table of Example 1:
		repeat through the table entry:
			let R be forcibly cast the rule entry;
			follow R for the number entry.

(Note that you shouldn’t use “it” as a variable, because “[it]” is a substitution from the adaptive text system.)

Thank you for this, zarf. Why is it that it seems every time I try to do something, it requires an I6 hack? :stuck_out_tongue: I’m going to start a different topic about what I’m trying to achieve and see if there’s a better way entirely to go about it.

This probably counts as a bug in the I7 compiler but I’m not sure how to frame it.