This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
donvoo's profile picture

OpenPeripherals Sensor help

Started by donvoo, 09 March 2014 - 06:36 PM
donvoo #1
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
Inumel #2
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
CometWolf #3
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
donvoo #4
Posted 10 March 2014 - 11:12 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
ok, so im using your way and when i enter in the name it says
attempt to concatenate string and table
CometWolf #5
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.