function CheckPlayers()
for i=1,#data do
--print(i)
ctrl = sensors.getController()
data = sensors.getSensors(ctrl)
proximitySensor = data[i]
data = sensors.getProbes(ctrl,proximitySensor)
playerProbe = data[3]
data = sensors.getAvailableTargetsforProbe(ctrl, proximitySensor, playerProbe)
--print(#data)
if(#data ~= 0) then
for j=1,#data do
playerTarget = data[j]
if playerTarget ~= nil then
if string.sub(playerTarget, 1, 2) == "vq" then
readings = sensors.getSensorReadingAsDict(ctrl, proximitySensor, data[j], playerProbe)
if(readings.name ~= nil) then -- Sometimes nil, Sometimes not nil...
print(readings.name.. "-" ..string.sub(playerTarget, 3))
else
print("name was nil")
end
end
end
end
end
end
end
while redstone.getInput("right") do
Monitor = peripheral.wrap("left")
Monitor.clear()
Monitor.setTextScale(2)
Monitor.setCursorPos(1,1)
Monitor.write("Entity Locator 2.0")
Monitor.setCursorPos(1,2)
Monitor.write("-------------------------------")
ctrl = sensors.getController()
data = sensors.getSensors(ctrl)
CheckPlayers()
sleep(0.1)
end
[Solved]
I'm trying to use 2 sensors, and the program recognizes the 2 sensors, but when I run the program It seems to just stop with no error. I have used a print(#data) to get how many sensors I had, and I had 2 yet it still quits the code unexpectedly with no error message. Here's the Code:
function CheckPlayers()
for i=1,#data do
--print(i)
proximitySensor = data[i]
data = sensors.getProbes(ctrl,proximitySensor)
playerProbe = data[3]
data = sensors.getAvailableTargetsforProbe(ctrl, proximitySensor, playerProbe)
--print(#data)
if(#data ~= 0) then
for j=1,#data do
playerTarget = data[j]
if playerTarget ~= nil then
print("Players nearby " ..playerTarget)
else
print("No one is around")
end
end
-nd
end
end
runs = 0
while runs < 20 do
Monitor = peripheral.wrap("left")
Monitor.clear()
Monitor.setTextScale(2)
Monitor.setCursorPos(1,1)
Monitor.write("Entity Locator 2.0")
Monitor.setCursorPos(1,2)
Monitor.write("-------------------------------")
ctrl = sensors.getController()
data = sensors.getSensors(ctrl)
CheckPlayers()
print("run")
sleep(1)
runs = runs+1
end
[/Solved]