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

Redstone signal in infinite loop

Started by naburus, 01 April 2013 - 09:46 AM
naburus #1
Posted 01 April 2013 - 11:46 AM
I wanna do that the Computer always scan the redstone signal in infinte loop. What is the problem in my code?


	while true do
			if redstone.getInput("left",true) then
					redstone.setOutput("right", true)
					sleep(4)
					redstone.setOutput("right", false)
					break
			end
	end

Give me this error massage: red:2 Too long without yielding
remiX #2
Posted 01 April 2013 - 12:01 PM
a while true do loop is an infinite loop and will last until stopped manually or in this case redstone signal on the left is on

Added a os.pullEvent('redstone') to before the last end. This causes it to yield and only continue if a redstone signal is triggered.

Also the if needs to be
if redstone.getInput( 'left' ) == true then
--or
if rs.getInputed( 'left' ) then
naburus #3
Posted 01 April 2013 - 12:02 PM
Hmm ok so i need add this line os.pullEvent('redstone') ty. Now works.