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

Gracefully stop a program?

Started by gronkdamage, 27 June 2013 - 01:50 AM
gronkdamage #1
Posted 27 June 2013 - 03:50 AM
I'm running a tunnel program, and I want to stop the program when I run out of a particular item.

I currently have 12 slots allocated to wood, 3 slots for glass, and 1 for torches. When I run out of wood, glass, or torches - I want the program to stop.

How do you stop a program gracefully?

I am basically doing something like this:

if turtle.getItemCount(12) < 1 then
stop
end

What is the key word to stop a program?
GopherAtl #2
Posted 27 June 2013 - 03:57 AM
error() will quit the program silently from any point in the code. To display a message without the usual error and line number prefixes, you can do, ex, error("Out of glass!",0). the 0 is important, and prevents displaying the line number.
gronkdamage #3
Posted 27 June 2013 - 04:06 AM
That's even better than what I wanted! Thanks! Awesome idea.