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

Help with reading tables from a file

Started by Toofifty, 08 March 2013 - 09:48 PM
Toofifty #1
Posted 08 March 2013 - 10:48 PM
EEDDIITT:: Worked it out. Item names should be in quotation marks.


Title: Help with reading tables from a file

I'm creating my own sorting system using computers and I'm having trouble with my client computer reading a table to translate from item name to item id.
This works properly in my central unit which opens the file and keeps count of the items, yet i get "serialize:1: table index expected, got nil" as an error in the client

This is the code (on both my client and CU)

local file = fs.open("nameItem","r")
local data = file.readAll()
file.close()
s = textutils.unserialize(data)

And this is the file it (the client) reads from:
{[Smoothstone]=1,[Cobblestone]=4,[StoneBricks]=98,[Obsidian]=49,[Netherrack]=87,[NetherBrick]=112,[EndStone]=121,[Sandstone]=24,[Dirt]=3,[Gravel]=13,[Sand]=12,[GrassBlock]=2,[SoulSand]=88,[Flint]=318,[IronIngot]=265,[GoldIngot]=266}

File the CU reads from (item counts), if it helps;
{[1]=0,[4]=0,[98]=0,[49]=0,[87]=0,[112]=0,[121]=0,[24]=0,[3]=0,[13]=0,[12]=0,[2]=0,[88]=0,[318]=0,[265]=0,[266]=0}

What am I doing wrong? And is there a more efficient way of doing this?
Lyqyd #2
Posted 09 March 2013 - 05:21 AM
Split into new topic.

OP answered his own question.