Jump to content




Table Handling


  • You cannot reply to this topic
5 replies to this topic

#1 metron80

  • Members
  • 55 posts
  • LocationSolitude, Skyrim

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:
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.

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 03 November 2014 - 02:17 AM

These are valid ways to declare keys in new tables:

local tabl = {i1 = {}}
local tabl = {["i1"] = {}}

... as opposed to:

local tabl = {"i1" = {}}


#3 valithor

  • Members
  • 1,053 posts

Posted 03 November 2014 - 02:20 AM

View Postmetron80, 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 metron80

  • Members
  • 55 posts
  • LocationSolitude, Skyrim

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 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 04 November 2014 - 12:12 AM

Yep, that'll work just fine.

#6 metron80

  • Members
  • 55 posts
  • LocationSolitude, Skyrim

Posted 04 November 2014 - 01:06 AM

Okay thanks! Appreciated! :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users