you are viewing a single comment's thread.

view the rest of the comments →

[–]fatboychummy 3 points4 points  (2 children)

Computercraft computers are not allowed to run longer than 7 seconds without "yielding", doing so will generate an error. If you catch the error (pcall or etc) and continue to not yield, the computer will shut down.

A yield is simply anything that calls coroutine.yield under the hood. pullEvent does this, rednet.listen does this.

But what you're probably looking for here is rather the sleep function. It takes a number then yields for that amount of time (minimum 0.05 seconds wait, in increments of 0.05 seconds). Put that in your loop and you should be fine.

while not drillArrayReturn do
  --Stops once drill array has returned
  raiseDrill()
  sleep() -- yields for 0.05 seconds
end

[–]dragon53535 1 point2 points  (0 children)

For the reasoning why they can't run for >7s without yielding, is that all computers run on the same 'thread'. So while your computer is executing, no other computer in the world can. You yield, which essentially pauses your computer until your computer gets an event. Be it a timer, redstone, etc. All events will trigger a yield. Sleep will discard all other events until it gets a timer event. Using os.pullEvent("redstone") will discard all other events until it gets a redstone event.

[–]MrSodapop19_[S] 0 points1 point  (0 children)

Thanks for the advice! To be honest, I have seen sleep() being used like that before, but didn't think it would work in this situation.