local tabl = {"i1" = {iType = "Bread", amount = "5", price = 1, sId = 84},"i2" = {iType = "Wheat", amount = "64", price = 2, sId = 0}, "i3" = {iType = "Seeds", amount = "4 1/2 Stks", price = 5, sId = 0}}
file = fs.open("shop", "w")
file.write(textutils.serialize(tabl))
file.close()
print("h")
error()
After that, I get the error "bios:339: [string "startup"]:1: "}" expected." The table is fine, and I see no error. Any help would be appreciated, thanks.
Table Handling
Started by metron80, Nov 03 2014 01:46 AM
5 replies to this topic
#1
Posted 03 November 2014 - 01:46 AM
Okay, so I have been trying to save items to a table. Currently, I am trying to save a serialized table to a file. Code:
#2
Posted 03 November 2014 - 02:17 AM
These are valid ways to declare keys in new tables:
... as opposed to:
local tabl = {i1 = {}}
local tabl = {["i1"] = {}}
... as opposed to:
local tabl = {"i1" = {}}
#3
Posted 03 November 2014 - 02:20 AM
metron80, on 03 November 2014 - 01:46 AM, said:
Okay, so I have been trying to save items to a table. Currently, I am trying to save a serialized table to a file. Code:
local tabl = {"i1" = {iType = "Bread", amount = "5", price = 1, sId = 84},"i2" = {iType = "Wheat", amount = "64", price = 2, sId = 0}, "i3" = {iType = "Seeds", amount = "4 1/2 Stks", price = 5, sId = 0}}
file = fs.open("shop", "w")
file.write(textutils.serialize(tabl))
file.close()
print("h")
error()
After that, I get the error "bios:339: [string "startup"]:1: "}" expected." The table is fine, and I see no error. Any help would be appreciated, thanks.You are essentially trying to save a table to a string. The problem here is the "il" = when you define the table.
edit: ninjaed
Edited by valithor, 03 November 2014 - 02:20 AM.
#4
Posted 03 November 2014 - 11:13 PM
Ok, so it would be this:
local tabl = {i1 = {iType = "Bread", amount = "5", price = 1, sId = 84}, i2 = {iType = "Wheat", amount = "64", price = 2, sId = 0}, i3 = {iType = "Seeds", amount = "4 1/2 Stks", price = 5, sId = 0}}
Not what was in the first post.
#5
Posted 04 November 2014 - 12:12 AM
Yep, that'll work just fine.
#6
Posted 04 November 2014 - 01:06 AM
Okay thanks! Appreciated!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











