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
OpenPeripherals Sensor help
Started by donvoo, Mar 09 2014 07:36 PM
4 replies to this topic
#1
Posted 09 March 2014 - 07:36 PM
#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
#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()
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
Posted 10 March 2014 - 11:12 PM
Inumel, 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
attempt to concatenate string and table
#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.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











