7 posts
Posted 28 December 2012 - 12:47 AM
Just having a bit off difficult writing a table and getting it to write data to a file so when the computer restart it start where it left off.
i have a computer get inputs and it is counting them just wount it to wire it to a diffent file off each color input.
i did woult it as a function it is in a loop and i need it to keep counting the input.
i have over 30 or more file it will need to wirte every time it loops and it will read the files on start up
or do i have to put witre in every time it counts i just did not wount to do that as it is on a sever and i type slow
818 posts
Posted 28 December 2012 - 01:10 AM
how much do you know in regards of fs API and tables?
2088 posts
Location
South Africa
Posted 28 December 2012 - 01:24 AM
file.write(textutils.serialize(t_table))
7508 posts
Location
Australia
Posted 28 December 2012 - 01:39 AM
and to answer the next potential question that will come… To get back from remiX's solution
t_table = textutils.unserialize( file_contents )
More info can be seen here: http://www.computerc.../Textutils_(API)
7 posts
Posted 05 January 2013 - 04:43 PM
yer no i dont under stand that
i have done it like this for now but i have cant sem to work out how to get it back in to the code at the startup of it as it is all read in a lop
t = {{"orange", orange} , {"lightBlue", lightBlue} , {"state" , state}}
if i == 4 then
i = 1
end
file = fs.open(t[i][1], "w")
file.write(t[i][2])
file.close()
i = i + 1
2005 posts
Posted 05 January 2013 - 05:36 PM
You don't initialize i that I can see. Maybe you did that outside of the loop? Also, what are the values of orange, lightBlue,and state? Those should have been variables declared and initialized elsewhere, otherwise you are just trying to open a file with nil as the name. And not "nil", which would work, the bad kind of nil that is not a value.
No, I'm crosseyed. It's when you write to the file that you might or might not be writing nil. Anyway, that still won't work. We need to see the loop, the initialization of i, and the last value assignments for orange, lightBlue, and state.
Edited on 05 January 2013 - 04:38 PM
7 posts
Posted 07 January 2013 - 11:44 PM
thanks
i now understand it i trout I did not but i went back over the code and fond a spell mistake
file.write(textutils.serialize(t_table))
and to answer the next potential question that will come… To get back from remiX's solution
t_table = textutils.unserialize( file_contents )
More info can be seen here: http://www.computerc.../Textutils_(API)
thanks for your help it is easy to have it all in one file thanks