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

ccSensor and ComputerCraft, Only able to get readings at a certain point?

Started by Ducklet, 20 January 2013 - 02:34 PM
Ducklet #1
Posted 20 January 2013 - 03:34 PM
As remix asked on post #11, " are you experiencing times where it will display the readings and other times it will not, even though you're within range of both occasions?", yes. It only works at certain points that should be in the range of the sensor.. Is there any fix to this? Or is it just a bug with ccSensors?


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]
theoriginalbit #2
Posted 20 January 2013 - 03:38 PM
I'd say it has something to do with your logical structure with the function… try putting the sensors.getSensors( ctrl ) above the function…

A tutorial written by myself and remiX… http://www.computercraft.info/forums2/index.php?/topic/9490-how-to-use-ccsensors/page__pid__77670#entry77670
Ducklet #3
Posted 20 January 2013 - 03:41 PM
I'd say it has something to do with your logical structure with the function… try putting the sensors.getSensors( ctrl ) above the function…

A tutorial written by myself and remiX… http://www.computerc...7670#entry77670

I created the function in an effort to try and fix this. It doesn't work with it all in the while loop either.

EDIT: Also wanted to add, this works for one Sensor if I take the loops out. I want this to work for multiple sensors so on a server I can have sensors everywhere, thus allowing me to see the location of everyone on the server.. or at least in the areas I want.
theoriginalbit #4
Posted 20 January 2013 - 03:53 PM
doing this should work ( untested, but based off the tutorial I made and what you have, I'm trying to keep it as similar to yours as possible… )

http://pastebin.com/7RwsgAqG
Ducklet #5
Posted 20 January 2013 - 03:56 PM
doing this should work ( untested, but based off the tutorial I made and what you have, I'm trying to keep it as similar to yours as possible… )

http://pastebin.com/7RwsgAqG

Got it. I just had to re-define ctrl and data in the for loop. :D/> thanks though

One more question, do you know how to get the player's name with proximity?
theoriginalbit #6
Posted 20 January 2013 - 03:59 PM
doing this should work ( untested, but based off the tutorial I made and what you have, I'm trying to keep it as similar to yours as possible… )

http://pastebin.com/7RwsgAqG

Got it. I just had to re-define ctrl and data in the for loop. :D/> thanks though

One more question, do you know how to get the player's name with proximity?
I'm not sure that its possible with ccSensors… there is a big bug where I think its meant to get the name but instead it returns the internal name of the Entity so for players its like qr or something… and pigs are like wb, etc etc etc…
Ducklet #7
Posted 20 January 2013 - 04:02 PM
doing this should work ( untested, but based off the tutorial I made and what you have, I'm trying to keep it as similar to yours as possible… )

http://pastebin.com/7RwsgAqG

Got it. I just had to re-define ctrl and data in the for loop. :D/> thanks though

One more question, do you know how to get the player's name with proximity?
I'm not sure that its possible with ccSensors… there is a big bug where I think its meant to get the name but instead it returns the internal name of the Entity so for players its like qr or something… and pigs are like wb, etc etc etc…

Yea, if I look at the readings in the actual sensor I can get everything about the player.. max health, what they are holding, name, current health, armor value, etc. I would love to have that info in my control room on my pvp server..
theoriginalbit #8
Posted 20 January 2013 - 04:05 PM
Yea, if I look at the readings in the actual sensor I can get everything about the player.. max health, what they are holding, name, current health, armor value, etc. I would love to have that info in my control room on my pvp server..
Thats odd… On the version I tested with I can get their Java Class and their coordinate… Tekkit? And is it that code you supplied before?
Ducklet #9
Posted 20 January 2013 - 04:08 PM
Yea, if I look at the readings in the actual sensor I can get everything about the player.. max health, what they are holding, name, current health, armor value, etc. I would love to have that info in my control room on my pvp server..
Thats odd… On the version I tested with I can get their Java Class and their coordinate… Tekkit? And is it that code you supplied before?

I can get their coordinates but there is sooo much more info if you look in the sensor itself. I'm on Tekkit and here's my working code so far. (it gives me vq x,y,z)

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)
  --[[readings = sensors.getSensorReadingAsDict(ctrl, proximitySensor, data[1], playerProbe)
  for k=1, #readings do
   print(readings[k])
  end
  --]]
  --print(#data)
  if(#data ~= 0) then
   for j=1,#data do
    playerTarget = data[j]
    if playerTarget ~= nil then
	 print("Players nearby " ..playerTarget)
    end
   end
  end
end
end

runs = 0
while runs < 200 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)
runs = runs+1
end

theoriginalbit #10
Posted 20 January 2013 - 04:53 PM
ok here is a test I just ran myself using this code

http://pastebin.com/6a1YrjrD

this is all the data that I was able to get from the sensors about a player…
remiX #11
Posted 20 January 2013 - 08:12 PM
When you get the readings, readings.name should be the player name of the selected target. Yeah the targets become qr which is really annoying.

Ducklet, are you experiencing times where it will display the readings and other times it will not, even though you're within range of both occasions?
Ducklet #12
Posted 21 January 2013 - 02:10 AM
When you get the readings, readings.name should be the player name of the selected target. Yeah the targets become qr which is really annoying.

Ducklet, are you experiencing times where it will display the readings and other times it will not, even though you're within range of both occasions?

I'll try readings.name, and not really

EDIT: Yes.. Yes I am. the readings.name only works at certain points… :/