Jump to content




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


  • You cannot reply to this topic
5 replies to this topic

#1 AndreWalia

  • Members
  • 294 posts
  • LocationSt.Louis, MO

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.

#2 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

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


#3 AndreWalia

  • Members
  • 294 posts
  • LocationSt.Louis, MO

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

#4 Doyle3694

  • Members
  • 815 posts

Posted 05 December 2012 - 09:33 AM

-snip-

#5 ChunLing

  • Members
  • 2,027 posts

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.

#6 AndreWalia

  • Members
  • 294 posts
  • LocationSt.Louis, MO

Posted 05 December 2012 - 10:33 AM

View PostChunLing, on 05 December 2012 - 10:24 AM, said:

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





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users