my code is here: http://pastebin.com/c4rHJsFK
the data in the file is:
{[1]=22256,[2]=262,[3]=332,}
{[1]=813,[2]=22256,[3]=22303,}
{[1]=22256,[2]=262,[3]=332,}
{[1]=813,[2]=22256,[3]=22303,}
local tables = {} -- Stores all the tables
local handle = fs.open("recipes", "r")
while true do
local text = handle.readLine()
if text then
local recipe = textutils.unserialize(text)
if recipe then
table.insert(tables, recipe) -- tables:insert won't work 1.63
end
else
break
end
end
handle.close()
I will have over 100 of these recipes so t's easier to have it stored in a text file than in the programYou should be able to put all of the tables you're interested into a single larger table, and then have that table be stored in the file.
this was exactly what I wanted thank you !You could use the following lines of code to read each line of the file then add the table read to a big table (assuming "recipes" is the file in which you saved the tables)local tables = {} -- Stores all the tables local handle = fs.open("recipes", "r") while true do local text = handle.readLine() if text then local recipe = textutils.unserialize(text) if recipe then table.insert(tables, recipe) -- tables:insert won't work 1.63 end else break end end handle.close()
I meant just store the larger table in the external file. It also shouldn't be that difficult if you need to modify the file you already have.I will have over 100 of these recipes so t's easier to have it stored in a text file than in the programYou should be able to put all of the tables you're interested into a single larger table, and then have that table be stored in the file.
{{[1]=22256,[2]=262,[3]=332,},
{[1]=813,[2]=22256,[3]=22303,}}
local recipes = {}
local h = fs.open("recipes.txt", 'r')
for line in h.readLine do
table.insert(recipes, line)
end
h.close()
that won't work in any version of ComputerCraft, you'll get an attempt to call nil.tables:insert won't work 1.63
it worked perfectly for methat won't work in any version of ComputerCraft, you'll get an attempt to call nil.tables:insert won't work 1.63
no it won't, it will look in the table for a function called `insert` which won't exist unless you create it, if it doesn't find a value in the table it looks in the tables metatable not in the table API regardless of the ComputerCraft version… in summary, the only time it will work is in this caseit worked perfectly for me
local tbl = {}
function tbl.insert( self, value )
return table.insert( self, textutils.unserialize( value ) )
end
tbl:insert( "hello" )
to improve on Ajt86's responselocal recipes = {} local h = fs.open("recipes.txt", 'r') for line in h.readLine do table.insert(recipes, line) end h.close()
oops, thanks.Except you never actually call textutils.unserialize() on the read line