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

Why Isnt My Code Working?

Started by Th3RadMan, 02 September 2013 - 12:30 AM
Th3RadMan #1
Posted 02 September 2013 - 02:30 AM
I made this code but it isnt doing what i want it to do

it should send a redstone signal to the right if it has a signal from back and left. if it doesnt have a signal from back but it does on left, it should send pulses to the top intil it gets a signal

any help?


while true do
  os.pullEvent("redstone")
  liquid = rs.getInput("back")
    if liquid == true then
  rs.setOutput("right", true)
  sleep(5.75)
  rs.setOutput("right", false)
  sleep(.1)
    else
  reset = rs.getInput("back")
    if reset == true then
  break
    else
    while reset == false do
  rs.setOutput("top", true)
  sleep(.3)
  rs.setOutput("top", false)
  sleep(.3)
	   end
	 end
   end
end
GravityScore #2
Posted 02 September 2013 - 02:45 AM
Here you go, this should do what you want:

while true do
  os.pullEvent("redstone") -- wait for a singal
  if rs.getInput("back") and rs.getInput("left") then -- if there is a signal on both the back and left
    rs.setOutput("right", true) -- output to right
  else
    rs.setOutput("right", false) -- turn off the right if it is on
    if rs.getInput("left") then -- if we have a signal only on the left
      -- pulse the redstone once. It will continue pulsing due to the while loop until it gets a signal at the back
      rs.setOutput("top", true)
      sleep(0.3)
      rs.setOutput("top", false)
      sleep(0.3)
    end
  end
end
Th3RadMan #3
Posted 02 September 2013 - 02:59 AM
thanks a lot, just need a small change and not sure what would be most efficient (coding noob :P/> ) i need it to automaticlly re activate the loop after the end because it has to reset, without a new redstone signal from left