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

Looping program forces computer to shutdown.

Started by NeonZenith, 12 October 2012 - 05:53 AM
NeonZenith #1
Posted 12 October 2012 - 07:53 AM
Hey, Only start playing around with CC recently, so this is probably/hopefully easy to fix. I tried as best I could to fix it, with no success.

For some reason when I run this program, it works for about 5 seconds before the computer shuts down completely.
I will say, for the short while it works that the program runs how I want it to.


input = "top"
output = "left"
rs.setOutput(output, true)
while true do
if os.eventPull == "redstone" then
  if rs.getInput(input) == true then
   rs.setOutput(output, false)
   sleep(8)
   rs.setOutput(output, true)
  end
end
end
Luanub #2
Posted 12 October 2012 - 08:03 AM
os.eventPull is actually os.pullEvent() and it needs () at the end as it is a function

It would also be better to not use the if statement. Try this:

input = "top"
output = "left"
rs.setOutput(output, true)
while true do
os.pullEvent("redstone")  --halts the program and waits for a redstone event to fire
  if rs.getInput(input) == true then
   rs.setOutput(output, false)
   sleep(8)
   rs.setOutput(output, true)
  end
end
end
Fatal_Exception #3
Posted 12 October 2012 - 08:09 AM
I would imagine you're getting a "too long without yielding" error.


input = "top"
output = "left"
rs.setOutput(output, true)
while true do
  if os.pullEvent() == "redstone" then -- <<THIS
	if rs.getInput(input) then
	  rs.setOutput(output, false)
	  sleep(8)
	  rs.setOutput(output, true)
	end
  end
end

edit: ninja!
NeonZenith #4
Posted 12 October 2012 - 08:13 AM
Worked like a charm, thanks heaps!