Using openccsensors and a turtle to detect a player and open a door.
os.loadAPI("ocs/apis/sensor")
while true do
local prox = sensor.wrap("right")
local targets = prox.getTargets()
if targets == "" then
redstone.setOutput("bottom", false)
else
for k,v in pairs(prox.getTargets()) do
local ptest = prox.getTargetDetails(k)
if ptest.Name ~= "Player" then
redstone.setOutput("bottom", false)
else
redstone.setOutput("bottom", true)
end
end
end
end
Detection works correctly however walking away and back into range leads to the following error code.
test2:10: attempt to index ? (a nil value) Which should be this line if ptest.Name ~= "Player" then
I'm banging my head against the wall as to how to skip line 10 if there is no Player nearby.












