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

Too Long Without Yielding

Started by Abstract, 22 February 2012 - 02:13 PM
Abstract #1
Posted 22 February 2012 - 03:13 PM
I need some help with my program. What it should do is,output redstone to the left, if redstone comes from the front, stop outputting redstone to the right wait and reboot. this is my code:
startup:
while true do
shell.run"redside"
end
redside:
redstone.setOutput("right", true)
if redstone.getInput("front", true)
then redstone.setOutput("right", false)
sleep(10)
os.restart()
end
but if I reboot now, it works for only a couple of seconds and a error pops up which says 'Too long without yielding'. What did I do wrong?
luza #2
Posted 22 February 2012 - 03:27 PM
you forgot some brackets.


while true do
shell.run("redside")
end
Casper7526 #3
Posted 22 February 2012 - 03:28 PM
When your code just loops endlessly without yielding for a few seconds, you receive that error.

You should use a pullevent to only check when redstone is changed instead.

startup:

redstone.setOutput("right", true)
while true do
event, param = os.pullEvent()
   if event == "redstone" and redstone.getInput("front") == true then
   redstone.setOutput("right", false)
   sleep(10)
   redstone.setOutput("right", true)
   end
end
Abstract #4
Posted 22 February 2012 - 03:46 PM
When your code just loops endlessly without yielding for a few seconds, you receive that error.

You should use a pullevent to only check when redstone is changed instead.

startup:

redstone.setOutput("right", true)
while true do
event, param = os.pullEvent()
   if event == "redstone" and redstone.getInput("front") == true then
   redstone.setOutput("right", false)
   sleep(10)
   redstone.setOutput("right", true)
   end
end
[string "redside"]:4: 'then' expected
Don't know why I've typed everything like you
EDIT: works, had a spelling mistake <_</>/>