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

Openccsensors help redstone pulse when crouching

Started by tvc, 27 May 2013 - 12:03 AM
tvc #1
Posted 27 May 2013 - 02:03 AM
I am wondering what i would need to do to set a redstone pulse when a is crouching

something like

prox.getTargetDetails(digger191)
if is crouching == true then
rs.setOutput("right", true)

or something like that
Lyqyd #2
Posted 27 May 2013 - 02:12 AM
Something vaguely like that. Try this:


os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("top")
while true do
  local details = prox.getTargetDetails("digger191")
  if details.isCrouching then
    rs.setOutput("right", true)
  else
    rs.setOutput("right", false)
  end
  sleep(0.5)
end
tvc #3
Posted 27 May 2013 - 02:19 AM
Something vaguely like that. Try this:


os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("top")
while true do
  local details = prox.getTargetDetails("digger191")
  if details.isCrouching then
	rs.setOutput("right", true)
  else
	rs.setOutput("right", false)
  end
  sleep(0.5)
end

the programs run with no errors but does not output redstone signal when i crouch
Lyqyd #4
Posted 27 May 2013 - 02:51 AM
Is your minecraft name "digger191"?

Try running the ocs/programs/sensorview program to see what the information is, especially the correct key name for isCrouching (may be isSneaking). Use the arrow keys and page-up and page-down to look around at the information. Disable NEI temporarily by hitting O in your inventory to make page-up and page-down work.
tvc #5
Posted 27 May 2013 - 03:04 AM
my name is digger191 and it is isSneaking but it didnt more i even tried to set it to == true then

that also didnt work =[ lol
Lyqyd #6
Posted 27 May 2013 - 03:11 AM
It's apparently IsSneaking, with a capital I. Try this, make sure your sensor is on top:


os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("top")
while true do
  local details = prox.getTargetDetails("digger191")
  if details and details.IsSneaking then
	    rs.setOutput("right", true)
  else
	    rs.setOutput("right", false)
  end
  sleep(0.5)
end
tvc #7
Posted 27 May 2013 - 03:14 AM
I love you lol thank you so much

one more question tho

when i leave the are it breaks the program say nil target because it cant find me how to i fix this?
LordIkol #8
Posted 27 May 2013 - 07:15 AM
you have to use a loop insteadt of directly pointing at you as target.

sth like this:


os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("top")

while true do
local targets = prox.getTargets()
for name, basicDetails in pairs(targets) do
  if name == "digger191" then  --not sure if name is the minecraftname yould be sth else
   local details = prox.getTargetDetails(name)
	if details and details.IsSneaking then
	  rs.setOutput("right", true)
	else
	  rs.setOutput("right", false)
	end
  else
   rs.setOutput("right", false)
  end
end
  sleep(0.5)
end

greets Loki