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

Conputer shutting down mid program

Started by Mysticpoisen, 08 February 2016 - 05:40 PM
Mysticpoisen #1
Posted 08 February 2016 - 06:40 PM
Hey there, I'm not sure what to do here, I'm working on some code for a server that spawns mobs in a staggered way in a room. Now, for some reason in the middle of the program, the computer will restart. No error message, nothing the computer will simply shut down, every time. I've never seen this and I'm not sure why it's happening.

Here's my code(apologies for bad code)

The error happens in the middle of the any of the wave functions, so wave() through wave4(). If any help could be given it is greatly appreciated. I'm not sure what a computer shutdown means in computercraft. Is it a bug, or an error with my code?
Creator #2
Posted 08 February 2016 - 08:27 PM
Put print statements to know where exactly it happens.
Lupus590 #3
Posted 08 February 2016 - 08:41 PM
Pull some events, the VM is killing your program because it doesn't pull events. http://computercraft.info/wiki/Os.pullEvent
Bomb Bloke #4
Posted 09 February 2016 - 01:51 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're waiting for a redstone event down the bottom of the script, but not within the infinite loops within your wave functions.

Put print statements to know where exactly it happens.

When a system shuts down, its screen is cleared.