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

openperipherials sensor help

Started by DotaCross, 27 February 2015 - 09:38 PM
DotaCross #1
Posted 27 February 2015 - 10:38 PM
I'm fairly new to CC programming from scratch, most my experiance is with adapting basic programs to fit my needs so bare with me. I'm trying to design a simple program that looks for nearby players and prints the list to a monitor, however I'm having a hard time understanding the new syntax for the sensor.getPlayers. It outputs a table, however the table is always returned as something like "table: 6beec85", my question is how do you translate the table into names, or is there a better method that I'm just not seeing?
Bomb Bloke #2
Posted 28 February 2015 - 12:00 PM
for key, value in pairs(myTable) do
  print(key..": "..tostring(value))
end

Let's say you did this, and discovered that there's a sub-table in your first table with eg a key-name of "inventory", or somesuch. You'd then iterate through that:

for key, value in pairs(myTable.inventory) do
  print(key..": "..tostring(value))
end

… and so on.

If you're still stuck, post the code you're using.