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

Error: Too long without yielding

Started by xd_sven_xd, 01 December 2013 - 09:04 AM
xd_sven_xd #1
Posted 01 December 2013 - 10:04 AM
Hello, everyone today i programmed a programm (lol) that detects a redstone input and outputs a redstone signal for 10 seconds,
but after some seconds i get this error:
startup:2: Too long without yielding
here is my code:
[img]<a href=[/img]
Bubba #2
Posted 01 December 2013 - 10:34 AM
Your code is not in the post. However, too long without yielding signifies that you are using a loop of some kind without yielding. To fix this, there are several ways. One is to use sleep(n) where n is any integer larger than 0.05 (you could technically use 0, but it is in effect the same as using 0.05). Another method is to use an actual coroutine yield. You can simply copy/paste this at the end of your loop, but it looks like this:

os.queueEvent("yield_event")
coroutine.yield()

To use it, it would look like this:

while true do
  --#Do whatever you want here
  os.queueEvent("yield_event")
  coroutine.yield()
end
Edited on 01 December 2013 - 09:34 AM
Yevano #3
Posted 01 December 2013 - 11:32 AM
Using sleep to fix busy waiting errors is almost always a sign that you should really be waiting for an event. Queuing an event and yielding is even worse, since you're spinning the code around every tick. Since your code should only have to run when a redstone input changes, you should be pulling redstone events. If you aren't familiar with the event system, this guide seems to have the information you'll need.
Edited on 01 December 2013 - 10:32 AM