This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
YoYoYonnY's profile picture

textutils.serialize question

Started by YoYoYonnY, 30 December 2013 - 07:51 AM
YoYoYonnY #1
Posted 30 December 2013 - 08:51 AM
I'm not sure if I am on the right page, but why does my program error "Cannot serialize table with recursive entries". Can you explain what I did wrong? I dont need exact answers, just give me examples of situations pls.
Lyqyd #2
Posted 30 December 2013 - 10:22 AM
Split into new topic.

Don't bump nine-month old unrelated bug reports to ask a question, please.
Bomb Bloke #3
Posted 30 December 2013 - 04:20 PM
One cause might be because you're trying to put a pointer to the table in the table.

When a table is defined, your variable gets set up as a pointer to that table in memory (like a shortcut). If you make a copy the contents of that variable into another variable, what gets copied is the pointer, not the table:

local myTable1 = {345,345,45,6754,35132}
local myTable2 = myTable1

myTable2[3] = "Test"
print(myTable1[3])

Running the above should print out "Test", as both myTable1 and myTable2 point to the same table.

Given this, you can see that it's possible for an element in a table to point to that same table:

local myTable = {65,423,4,346,34}
myTable[1] = myTable

print(myTable[1][2])

When printing, the above should get the first element from the myTable table - which leads back to the same table! - then get the second element from that (423). This is a form of recursion.

If you try to serialise such a table, textutils will check myTable[1] and see a pointer to a table, which it'll then try to serialise. So the next step in doing that is to check myTable[1][1], which happens to contain a pointer to a table, leading it to check myTable[1][1][1], and so on until you run out of RAM to track the infinite loop you've just jumped into.

Hence rather then allowing you to try this, textutils just errors out as soon as recursion is detected.

Post the script you're having trouble with if you can't see how any of this applies.
Lyqyd #4
Posted 30 December 2013 - 04:56 PM
Another cause is multiple entries in a table pointing to the same table, since the serialize tracking just looks at tables it has seen at all, not whether the table reference is a parent of the current entry.
YoYoYonnY #5
Posted 26 January 2014 - 10:12 AM
Thanks for the help! I was indeed making a infinite loop of tables. :)/>