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

Peripheral:62:Too Long?

Started by CardingiSFun, 16 November 2014 - 09:50 PM
CardingiSFun #1
Posted 16 November 2014 - 10:50 PM
Soo i was coding a program for a mod called Big Reactors. And i got a random error.

Heres my code and the error

Spoiler

Spoiler
Bomb Bloke #2
Posted 16 November 2014 - 10:55 PM
When a computer/turtle starts running code, ComputerCraft starts a ten second timer. If that code doesn't yield before that timer ends then ComputerCraft will either crash the script or the whole computer (depending on the nature of the functions your script is calling). After each yield, any other systems waiting to run code do so, then after they've all yielded, processing continues with a new time limit.

The reason why is that running your code chews up valuable server processing power, and so it shouldn't be able to monopolise it. In fact, only ONE CC device can run code at a time: While one is doing something, none of the others can do anything until it yields.

Whether or not it takes more than ten seconds for your code to execute mostly depends on how often you allow it to yield (and, to a much lesser extent, on the horse power of the Minecraft server it's running on). Pulling events (eg getting typed characters or checking timers) triggers a yield, and many commands (eg turtle movements, sleeping, or getting text input from the user) have to pull events to work anyway.

In your script, you have a "while" loop near the bottom which doesn't yield at all. Stick a sleep(5) or something near the bottom.
Edited on 16 November 2014 - 09:57 PM