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

OpenPeripherals Sensor Player Data

Started by HandieAndy, 15 November 2016 - 10:29 AM
HandieAndy #1
Posted 15 November 2016 - 11:29 AM
So, as the title suggests, I am trying to detect players around a sensor, and retrieve the name and relative position of the player. However, I am having a bit of trouble with the sensor's

getPlayers()
and

getPlayerByName()
functions. I use the first to get the list of players, but because of testing, I can just index the first element, as there will be only one player, which works out fine. Then I use that name in the second function to try to get some more precise information about that player, but this function just returns a table of functions as elements, as I have found by trying to print the keys and values. Here's the exact test code I have:

local p = peripheral.wrap("back")

local name = p.getPlayers()[1].name
local data = p.getPlayerByName(name)

for i in pairs(data) do
  print(i)
end
The problem is, the output of that snippet is this:

listSources
getAdvancedMethodsData
all
listMethods
doc
keys
basic
select
single
How do I go from this list of methods to getting the relative position of the player, if I know their name?
HandieAndy #2
Posted 15 November 2016 - 06:44 PM
Actually, I found the answer to this. For anyone who might stumble across this later, to access the position data, simply get the table with

p.getPlayerByName(name).all().position