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

computercraft v1.58 and openPeripheral v0.2.1 sensor help

Started by roadkill613, 12 January 2014 - 05:14 PM
roadkill613 #1
Posted 12 January 2014 - 06:14 PM
i am trying to get the sensors to work. how ever there is no apis/sensor to load does anyone know if that was an oversight or is there a different api i need to call to get it to work?

sorry if this has been asked before but the search for sensor pulled up topics about how to load the api/sensor not what to do if there isnt one.


Edit i was informed below that in my example and version the sensor is part of openPeripheral not opencc so that explains why there is no apis/sensor. however that makes the issue worse because there is no information for openP sensors yet because its in the new version.
Edited on 12 January 2014 - 09:59 PM
CometWolf #2
Posted 12 January 2014 - 06:36 PM
The sensor api is for the mod openCCSensor, not openPeripherals… The OP sensor is pretty poorly documented however, so idk how to use it. Aside from sensor = peripheral.wrap("side") and then using a pairs loop to get the functions.
roadkill613 #3
Posted 12 January 2014 - 06:43 PM
ah well thats something i didnt know.

i will see if making a function for the sensor will work rather then trying to call an api that dose not belong to it anyway thankyou.

if anyone else has more info on this i would be all ears.. but till then i guess i will go dig around in the openPeripherals forum and see if i can find info there and report back. thank you all
subzero22 #4
Posted 12 January 2014 - 08:42 PM
Here's what I got from the openccsensor forum post.

http://www.computercraft.info/forums2/index.php?/topic/5996-164-cc-157-openccsensors/


-- load the API
os.loadAPI("ocs/apis/sensor")
-- wrap the sensor
prox = sensor.wrap("left")
-- get the targets
local targets = prox.getTargets()
-- loop through them
for name, basicDetails in pairs(targets) do
  -- print their name
  print("Found entity: "..name)
  -- get more details about them
  local moreDetails = prox.getTargetDetails(name)
  -- print their health
  print("Health: "..moreDetails.Health)
  print("------")
end
theoriginalbit #5
Posted 12 January 2014 - 08:43 PM
Here's what I got from the openccsensor forum post.
OpenPeripheral, not OpenCCSensors.
roadkill613 #6
Posted 12 January 2014 - 11:03 PM
i edited the OP to reflect what i have learned so far,, witch is only that the sensor is openP not openCC witch explains why there is no apis/sensor.

how ever googling for the solution has resulted in little to no info available because of the newer versions the modpak i am running witch is SGtekkit.

i am extremely new to computercraft and lack the knowledge to continue further without continuing my education in lua coding so thats what i am doing at this point. so thanks for the help. if you all know of any good tutorials other than the ones on this site please post them or message them to me. thanks
subzero22 #7
Posted 22 January 2014 - 01:09 PM
I almost forgot about this post to let you know what I found. I still haven't figured out how it all works yet but I did manage to get it to sense and paste on a monitor if someone is within range of the sensor.

fist you want to type this and it will show what you all can do with it.


m = peripheral.getMethods(side) -- side being where the side it's at.
c  =  1
for k, v in pairs(m) do
  print(v)
    if c  == 15 then
	  os.pullEvent("key")  -- so some of the text doesn't scroll off screen.
	  c = 1
    end
end


I'll post the code I got working so far when I can get back onto the game. Oh also when doing the peripheral for ae do it on the machine that powers the me system. I still can't figure out how to make it list all the items like I did with the me bridge but I know there's a way to do it from the list code I had up there. If you can figure it out please tell me.

Oh ya and untill I get the code from the server Its on here's kinda what I remember doing. not exact.


p = peripheral.wrap("side")

while true do
  n = p.getNameList()  -- it was something like that tward the bottom of the list.
  for k, v in pairs(n) do
    print(v)
  end
sleep(5)
end

I also threw some other code in there to send a redstone signal and turn on my me system only while I was near it.