Why are tables and variables behaving this way?

I have a Table that gets populated with items held by the player when a custom action is called.

I have a number variable that iterates as it counts through the items and puts both the current count number, and the item in a blank row.
I then clear the number variable ready for the next count.

However if I then display the contents of the table using a seperate debug action I use to show what was stored in the table…the numbers in the table show the current value of the variable…not the number initially stored.

so what should look like:

1 Book
2 Apple
3 Spoon

returns as either

3 Book
3 Apple
3 Spoon

or (if I reset the iteration variable)

0 Book
0 Apple
0 Spoon

i’m guessing what my input command is actually doing is a direct reference to the variable, as opposed to storing simply what it contains at that moment.
If that’s the case, how do you write/save current variable data before changing it?

Now the Index entry is “[ListThings]”;
// ListThings is the iteration counter: - ListThings = ListThings + 1 for each item held before the above table input command.

It’s hard to say without seeing the code producing the tables. Can you share a copy of that code, stripped down to show just the parts that illustrate how the table is filled in and read?

OK, I think I have worked out why the table was updating to show the current variable data.
If the variable name is in quotes it appears to be a reference to the variable, however if I just type:

Now the Index entry is ListThings;

It stores and maintains the old data.
The issue now is…I want the user to type and compare a number but this raises the whole snippet/number mismatch issue I was trying to avoid.
The players command is text but the Index entry is contents of a number variable.

The problem is that you’re saving the actual text substitution “[Listthings]” in each row of your table, so when you read back the contents it evaluates “[ListThings]” for each row, which evaluates to whatever ListThings currently is at the time of reading back, not at the time of storing…


Now the Index entry is the substituted form of “[ListThings]”; 

which forces the evaluation to take place before it’s stored in the table, rather than when it’s read back.

See 20.7 in the documentation.

1 Like

Thanks drpeterbatesuk…

That did the trick!

If you include a [number] token in the “Understand … [number]… as …ing” phrase you’re using to parse the player’s input, the number entered is available as ‘the number understood’.


Choosing is an action applying to one number.
Understand "choose [number]" as choosing.
If the number understood is the Index entry....

I assume you could make an action that understands just “[number]” as the action?

The idea is the player just types the number, so not ‘choose 1’, but ‘1’


Understand "[number]" as choosing.

Unhelpful side note: When I first glanced at this topic title in the new posts, my brain parsed it as being about furniture (tables) that were jumping around the room or something. “Why are tables behaving this way? Why is there so much trouble in this world?!”


Never forget to feed your tables properly, or they get hangry.