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

From file to table?

Started by ReBraLaCC, 20 October 2015 - 12:05 PM
ReBraLaCC #1
Posted 20 October 2015 - 02:05 PM
I am trying to make a OS/UI, and i need to get a table out of a file what is the best way to do it??

i am now using:


file = fs.open(path,"r") – path is actually a real path!
local Buttons = file.readAll()
file.close()


Any way to fix this??

(If there is any wrong English i am sorry from Holland :D/>)
TYKUHN2 #2
Posted 20 October 2015 - 08:21 PM
textutils.unserialize(Buttons) (American version)
Edited on 20 October 2015 - 06:21 PM
Bomb Bloke #3
Posted 20 October 2015 - 10:37 PM
Er, wouldn't that be…?

local Buttons = textutils.unserialise(file.readAll())

The file would need to contain nothing but the table structure. Experiment with textutils.serialise(someTable) for examples of what you can put in it.
TYKUHN2 #4
Posted 20 October 2015 - 11:04 PM
Either way works since buttons would equal the content and as long as my example is set to something it will be reuseable.
KingofGamesYami #5
Posted 20 October 2015 - 11:08 PM
Either way works since buttons would equal the content and as long as my example is set to something it will be reuseable.

…which you didn't show in your post. Your post would imply using textutils.serialize on the variable would make the variable a table, when in fact that is impossible to do in Lua.
TYKUHN2 #6
Posted 20 October 2015 - 11:39 PM
The variable is a string of data that is in this case assumed to be a serialised table.
ReBraLaCC #7
Posted 21 October 2015 - 10:02 AM
Thanks it works !!!