Jump to content




OpenPeripherals Sensor help


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

#1 donvoo

  • New Members
  • 2 posts

Posted 09 March 2014 - 07:36 PM

Ok so im still learning lua scipting and ive just started to use stuff like
for key, value in pairs() do

so to the problem, the server i play on just recently added OpenPeripherals, and i noticed the sensors and thought they are toltally cool after finding all the things you can do with them. I was mainly interested in the sensor.getPlayerData() command. When i use the code


local sensor = peripheral.wrap("back")
local tableInfo = snsor.getPlayerData(read())
for key, value in pairs(tableInfo) do
print(key.. " = " .. tostring(value))
end


when i use this code it displays a bunch of things about the player.
though some things such as armor shows up as
armor = table: (some random number here)
all im wondering is how would i get this to show up?

sorry if my post is not perfect

#2 Inumel

  • Members
  • 120 posts

Posted 09 March 2014 - 08:20 PM

You would run it through another for loop
local sensor = peripheral.wrap("back")
local tableInfo = sensor.getPlayerData(read())
for key, value in pairs(tableInfo) do
  for z,y in pairs(value) do
    print(z.." = "..y)
  end
--#  print(key.. " = " .. tostring(value))
end


#3 CometWolf

  • Members
  • 1,283 posts

Posted 09 March 2014 - 08:21 PM

Use code tags next time.

To get the info from a table, you would do what you're already doing, use a pairs loop. To determine when the variable is a table, use type()
if type(variable) == "table" then
local sensor = peripheral.wrap("back")
local tableInfo = snsor.getPlayerData(read())
for key, value in pairs(tableInfo) do
  if type(key) == "table" then
    for key2,value2 in pairs(key) do
	  print(key2.. " = " .. tostring(value2))
    end
  else
    print(key.. " = " .. tostring(value))
  end
end


#4 donvoo

  • New Members
  • 2 posts

Posted 10 March 2014 - 11:12 PM

View PostInumel, on 09 March 2014 - 08:20 PM, said:

You would run it through another for loop
local sensor = peripheral.wrap("back")
local tableInfo = sensor.getPlayerData(read())
for key, value in pairs(tableInfo) do
  for z,y in pairs(value) do
	print(z.." = "..y)
  end
--#  print(key.. " = " .. tostring(value))
end
ok, so im using your way and when i enter in the name it says
attempt to concatenate string and table

#5 CometWolf

  • Members
  • 1,283 posts

Posted 11 March 2014 - 05:22 AM

Use tostring on y, and bam another table reference. This is a silly way of checking all the info, use the lua console instead and just loop the tables that interest you.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users