66 posts
Location
Minecraft world
Posted 18 April 2017 - 05:48 AM
So i'm trying to get an variable from a table and this is how i'm trying to do it but when i call print it prints blank
Retrive and load table code (Not working)
function load(name)
local file = fs.open(name,"r")
local data = file.readAll()
file.close()
return textutils.unserialize(data)
end
tabl = load("root/system/configs/AppPos.conf")
print(tabl)
print(ypos)
print(xpos)
This is the table (Think its working)
{
app = "Lua_Shell",
xpos = "10",
ypos = "5",
}
726 posts
Location
Rem is best girl
Posted 18 April 2017 - 09:44 AM
load is already a function in lua.
13 posts
Posted 18 April 2017 - 12:20 PM
print(tabl.xpos)
print(tabl.ypos)
I believe that should work
353 posts
Location
Orewa, New Zealand
Posted 19 April 2017 - 05:44 AM
The content of AppPos.conf would be helpful, perhaps the un-serialization is failing.
This clearly won't work as you are not indexing the table, instead you are printing 'xpos' and 'ypos' in the environment.
print( xpos )
print( ypos )
What happens if you change them to
print( tabl.xpos )
print( tabl.ypos )
If 'attempt to index boolean/nil/?' appears, this indicates that 'tabl' is not a table, so 'textutils.unserialise' is failing.
What does `print( type( tabl ) )` output? If it anything but 'table' then the AppPos.conf is likely invalid so textutils.unserialise cannot make a table out of it.
66 posts
Location
Minecraft world
Posted 19 April 2017 - 02:10 PM
The content of AppPos.conf would be helpful, perhaps the un-serialization is failing.
This clearly won't work as you are not indexing the table, instead you are printing 'xpos' and 'ypos' in the environment.
print( xpos )
print( ypos )
What happens if you change them to
print( tabl.xpos )
print( tabl.ypos )
If 'attempt to index boolean/nil/?' appears, this indicates that 'tabl' is not a table, so 'textutils.unserialise' is failing.
What does `print( type( tabl ) )` output? If it anything but 'table' then the AppPos.conf is likely invalid so textutils.unserialise cannot make a table out of it.
print(tabl.xpos)
print(tabl.ypos)
I believe that should work
Thanks you 2 it works now by doing table.xpos!
Thanks