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

Infinite Program Loop on Startup

Started by Holtster2000, 28 July 2014 - 07:16 PM
Holtster2000 #1
Posted 28 July 2014 - 09:16 PM
I created a program to control a force field and edited the startup program to run it like this:

while true do
shell.run("gate")
end

Now I want to tweak the program but I am unable to terminate it. Instead, it keeps running and I labeled the computer so breaking it does nothing.
Please help!
Edited on 28 July 2014 - 07:46 PM
Bubba #2
Posted 28 July 2014 - 09:54 PM
Fortunately this is a pretty simple issue to take care of.

Go ahead and craft yourself another computer, a disk drive, and a floppy disk. Set the disk drive down next to the newly crafted computer and insert the floppy disk into the disk drive. Start up the computer and type "edit disk/startup". It will open the editor: at this point just save and close the file – you do not need any content in the startup file. Pick up the disk drive and floppy and move it to the computer that is stuck in a loop. Once you've put the floppy disk in, you can start your computer and the computer startup code will be bypassed in favor of the blank startup file on the floppy disk.

However, I should note that if you cannot terminate the program, it is probably due to a lack of "sleeping" in your code. For example, say you have a while loop like this:

while true do
  print(1+1)
end

This code never sleeps, and is therefore very difficult to terminate (ComputerCraft is supposed to have protections against this sort of thing, but I've found that on slower computers they do not work as well).

In order to help with the termination issue, I usually add a simple sleep(0.05) statement at the bottom or top of my loops:

while true do
  print(1+1)
  sleep(0.05)
end

Now the code should be easily terminated and you won't have to deal with floppy disks.
Edited on 28 July 2014 - 07:54 PM