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

Help with Big Reactors reactor control

Started by faolan89, 24 December 2015 - 06:49 AM
faolan89 #1
Posted 24 December 2015 - 07:49 AM
i wrote a program to control a reactor from Big Reactors on Tekkit legends. My problem is that something is causing the advanced computer to shutdown and I am not sure what because there is no error message I have tried multiple different things and it was working somewhat correctly at one point. It is usually ran on an advanced monitor on the right side. The program is at http://pastebin.com/YwdmQ4gQ.
Bomb Bloke #2
Posted 24 December 2015 - 09:06 AM
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 may 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 has a little to do with the power of the Minecraft server it's running on, and a lot to do with how often you allow your code to yield. 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. Basically, anything that triggers a pause is pulling an event in order to do it, and in order to pull an event the code yields.

In your code, you've got a loop down the bottom (starting at line 46) which attempts to repeat forever without pulling any events (instead, it just examines the one you pulled before starting the loop over and over again). Move lines 35-44 into that loop.

You're also missing some brackets on line 19.
faolan89 #3
Posted 24 December 2015 - 10:01 AM
Thanks. Got it working perfectly now