Jump to content




Get variable from Table


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

#1 danielsv03

  • Members
  • 66 posts
  • LocationMinecraft world

Posted 18 April 2017 - 04: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",
}


#2 TheRockettek

  • Members
  • 547 posts
  • LocationRem is best girl

Posted 18 April 2017 - 08:44 AM

load is already a function in lua.

#3 Wilobate

  • Members
  • 13 posts

Posted 18 April 2017 - 11:20 AM

print(tabl.xpos)
print(tabl.ypos)

I believe that should work

#4 hbomb79

  • Members
  • 352 posts
  • LocationOrewa, New Zealand

Posted 19 April 2017 - 04: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.

#5 danielsv03

  • Members
  • 66 posts
  • LocationMinecraft world

Posted 19 April 2017 - 01:10 PM

View Posthbomb79, on 19 April 2017 - 04:44 AM, said:

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.

View PostWilobate, on 18 April 2017 - 11:20 AM, said:

print(tabl.xpos)
print(tabl.ypos)

I believe that should work


Thanks you 2 it works now by doing table.xpos!

Thanks





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users