Jump to content




Insert variables into tables [SOLVED]

api computer utility

2 replies to this topic

#1 danielsv03

  • Members
  • 66 posts
  • LocationMinecraft world

Posted 01 May 2017 - 04:54 PM

Hello so i'm trying to insert like name = "name here" into this table



{
  "yeee",
  ypos = 2,
  xpos = 2,
}



soo far i been trying to do this


function load(name)
local file = fs.open(name,"r")
local data = file.readAll()
file.close()
return textutils.unserialize(data)
end

function save(table,name)
local file = fs.open(name,"w")
file.write(textutils.serialize(table))
file.close()
end


tabl = load("root/system/Apps/Lau_Shell/Config.conf")
--root/system/configs/AppPos.conf
print(tabl)
print(tabl.ypos)
print(tabl.xpos)
lua_icon = paintutils.loadImage("root/system/Apps/Lau_Shell/lua_shell.icon")
paintutils.drawImage(lua_icon, tabl.ypos, tabl.xpos)
a = {name = hello)
tab = {tabl}
table.insert(tabl, a)

save(tabl, "root/system/Apps/Lau_Shell/Config.conf")


I want it too look like this

{
  "yeee",
  ypos = 2,
  xpos = 2,
  name = "name_here",
}



btw the path is correct it leads to the table

Thx

Edited by danielsv03, 01 May 2017 - 06:11 PM.


#2 Goof

  • Members
  • 751 posts

Posted 01 May 2017 - 06:06 PM

Instead of
a = {name = hello) --# the variable 'hello' is not defined. (Use as string form "hello")
tab = {tabl} --# why define this if you do not use it?
table.insert(tabl, a) --# inserts a (Which is just an empty table) to the tabl reference

You could do
tabl.name = "Hello" --# Directly changes the name index of the table to the desired value ("Hello")

That would directly change the tabl reference and add/change the name to the desired string/value.

However I am not entirely sure what your problem is.

I also found a syntax error, which may just be a typo, but who knows :)
a = {name = hello)
                 ^

Edited by Mikk809h, 01 May 2017 - 06:06 PM.


#3 danielsv03

  • Members
  • 66 posts
  • LocationMinecraft world

Posted 01 May 2017 - 06:10 PM

 Mikk809h, on 01 May 2017 - 06:06 PM, said:

Instead of
a = {name = hello) --# the variable 'hello' is not defined. (Use as string form "hello")
tab = {tabl} --# why define this if you do not use it?
table.insert(tabl, a) --# inserts a (Which is just an empty table) to the tabl reference

You could do
tabl.name = "Hello" --# Directly changes the name index of the table to the desired value ("Hello")

That would directly change the tabl reference and add/change the name to the desired string/value.

However I am not entirely sure what your problem is.

I also found a syntax error, which may just be a typo, but who knows :)
a = {name = hello)
				 ^



Thanks for the Support it now works :D I'm so glad you could spend your time on helping me :D Thx a lot!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users