Posted 31 July 2013 - 05:14 PM
Hey all, I'm having a bit of an issue with openCCsensors and receiving results from the table. I have the following code:
It works fine until a player enters or leaves the area that the proximity sensor can detect, and then it returns an error "startup:14: attempt to index ? (a nil value)", which from what I understand is the code not being able to find the Name in the table that openCCsensors provides.
How would I go about fixing this so the code doesn't break when someone enters/leaves, and have it update to show the change?
os.loadAPI("ocs/apis/sensor")
local mon = peripheral.wrap("back")
local prox = sensor.wrap("top")
local targets = prox.getTargets()
term.redirect(mon)
term.clear()
while true do
term.setCursorPos(1,1)
for target in pairs(targets) do
local info = prox.getTargetDetails(target)
if info.Name == "Player" then
print("Player: "..info.Username)
print("( "..info.Position.X..", "..info.Position.Y..", "..info.Position.Z.. " )")
print("-------------------------------------------------------------")
sleep(0.5)
end
end
end
It works fine until a player enters or leaves the area that the proximity sensor can detect, and then it returns an error "startup:14: attempt to index ? (a nil value)", which from what I understand is the code not being able to find the Name in the table that openCCsensors provides.
How would I go about fixing this so the code doesn't break when someone enters/leaves, and have it update to show the change?