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

World closes when i use a t-flip-flop program

Started by AndreWalia, 05 December 2012 - 07:19 AM
AndreWalia #1
Posted 05 December 2012 - 08:19 AM
Ok so the code is

while true do
  if redstone.getInput("left") then
    if redstone.getOutput("right") then
	  redstone.setOutput("right",false)
    else
	  redstone.setOutput("right",true)
    end
  end
end
when i run it it works fine but when i press the button to the left of it while the program is on my world just closes and it says Server Closing or something like that.
Cranium #2
Posted 05 December 2012 - 08:27 AM
Your program wouldn't do that. There must be something wrong witht he installation of your mods. Do you have any other mods?

(quick note/improvement)

while true do
    local event, p1 = os.pullEvent()
    if event == "redstone" and rs.getInput("left") then
	    if rs.getOutput("right") then
		    rs.setOutput("right", false)
	    else
		    rs.setOutput("right", true)
	    end
    end
end
AndreWalia #3
Posted 05 December 2012 - 08:36 AM
Never mind i fixed it. it was doing the loop again before the redstone signal stopped. here is what worked.

while true do
  if redstone.getInput("left") then
    if redstone.getOutput("right") then
	  redstone.setOutput("right",false)
    else
	  redstone.setOutput("right",true)
    end
    sleep(4)
  end
  sleep(0.001)
end
so yeah
Doyle3694 #4
Posted 05 December 2012 - 09:33 AM
-snip-
ChunLing #5
Posted 05 December 2012 - 10:24 AM
Use an os.pullEvent("redstone") so that you only run this when there is actually a change in the redstone inputs. There is no reason to be running this so much faster than the world tick rate, and there is no reason to do anything if there isn't a change in the redstone inputs.
AndreWalia #6
Posted 05 December 2012 - 10:33 AM
Use an os.pullEvent("redstone") so that you only run this when there is actually a change in the redstone inputs. There is no reason to be running this so much faster than the world tick rate, and there is no reason to do anything if there isn't a change in the redstone inputs.
Cool. I never knew about that event. Thanks