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

Very basic peripheral help - big reactors

Started by AdrenalineDM, 20 March 2015 - 03:41 AM
AdrenalineDM #1
Posted 20 March 2015 - 04:41 AM
I am trying to create a script simple enough to constantly tell me the current state of a selected big reactor (online of offline), and have a power button under it which can toggle the power on and off. I have been going through a tutorial on monitor buttons and using some of the information to create my own script.
So far I have worked out a bunch of bugs, and though it may not be pretty, it almost works.


I am getting this error around less than 5 seconds after pressing the power button on my monitor, which succeeds at turning on the power of the big reactor, as well as returning the state of the reactor to the computer.


This is my code
http://pastebin.com/yn7274av

I'm next to certain that this error is coming from having the computer constantly checking for the reactors status, but I'm not sure how to do it any other way.
Help would be very much appreciated

edit: Also, I am aware that I don't have anything in my script that will toggle the state of the reactor. I am not yet there in the tutorial



Solved the issue above, and am now having another one. I am having trouble running two sets of nearly the same code on the same monitor?
I am trying to have a big monitor showing the status of multiple reactors
So I hook up a separate computer to the big reactor peripheral control, and when I try to run both programs at the same time, some stuff shows up, and some stuff doesnt.
The buttons work, and the option to toggle the reactor on/off works, but it doesn't show the buttons, the labels on the buttons, or "reactor # status" heading for my second computer (it only shows the labels and buttons of the computer that just got the program written into it.)

Code is pretty much the same, except for moving the labels/buttons to the side.

http://pastebin.com/0ZiCwSYJ

Edited on 20 March 2015 - 05:38 AM
Bomb Bloke #2
Posted 20 March 2015 - 05:11 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 pull one monitor_touch event, then start another loop (on line 59) which repeats forever so long as the reactor is active, without yielding. You likely want to remove that second loop, leaving its content within the loop you already defined on line 44.