Hello,
I am working on an OS for ComputerCraft. In it, I have a serialized table in a file that is read by the program and the keys are displayed in a row. I want the keys to be displayed in a specific order, but they are always re-arranged into an order I do not want.
In the file, the keys are in the order {"File", "Edit", "View", "Go", "Window"}.
In the row, the text is in the order {"View", "Edit", "Window", "File", "Go"}.
I cannot change the order in the program because the program has to be portable for other files like this one. Is this a bug? Is there anyway I can fix this problem? I am running CraftOS 1.7.
Thanks, Jack
2
textutils.unserialize() rearranging items in table
Started by JackMacWindows, Jul 24 2016 03:00 PM
lua api
4 replies to this topic
#1
Posted 24 July 2016 - 03:00 PM
#2
Posted 24 July 2016 - 08:36 PM
The problem is probably not the serialization I just checked it, everything works fine, what do you use to display the texts?
#3
Posted 24 July 2016 - 09:09 PM
Let's see your actual table, please. If you're using textual keys, there is no "order" of elements inherent in the table.
#4
Posted 26 July 2016 - 03:19 AM
Lyqyd, on 24 July 2016 - 09:09 PM, said:
Let's see your actual table, please. If you're using textual keys, there is no "order" of elements inherent in the table.
Spoiler
I print with:for l,x in pairs(menulist) do write(" " .. l) endwhere menulist is a table with the names.
#5
Posted 26 July 2016 - 03:27 AM
Your table is using strings ("View", "Window", etc.) as keys, so there is no inherent order to the table. If you want the table to be in a specific order, you might have to structure your entries a little differently:
Note that the inner tables (which contain the "name" and "contents" keys) will be implicitly assigned numeric keys when they are declared this way.
{ { name = "File", contents = { ["New Folder"] = "-newfol", Print = "-print", ["New Window"] = "-newwin", } }, { name = "Edit", contents = { Cut = "_cut", Paste = "_paste", Undo = "-undo", Copy = "_copy", } }, }
Note that the inner tables (which contain the "name" and "contents" keys) will be implicitly assigned numeric keys when they are declared this way.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users