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

shutting off a program

Started by TwitchBlade, 09 March 2014 - 01:16 AM
TwitchBlade #1
Posted 09 March 2014 - 02:16 AM
is there any way to shut off a program from inside the program for instance i have a button program that displays things on a monitor is there any way to have a button that shuts of the program but not shuting off the computer or rebooting it(because it is startup and that would just run it agian)
Lyqyd #2
Posted 09 March 2014 - 03:37 AM
Hold Ctrl-T for a moment.
twormtwo #3
Posted 09 March 2014 - 07:39 AM
If you are not executing this from a function, you can use "return" to end a program there.
Example:

while true do
  print("Type the correct word to end the program!")
  input = read()
  if input == "the correct word" then
    print("You got it!")
    return
  else
    print("Try again!")
  end
end
The program will end after it prints "You got it!"
oeed #4
Posted 09 March 2014 - 08:24 AM
I think the other replies, especially Lyqyd's, have misunderstood what you're asking.

It really depends on what your code looks like. If you have a while loop then you need to do something like this:


local shouldContinue = true
function quit()
  shouldContinue = false
end
--make sure all your functions are above the while loop (or if it's in a function call it at the end)
while shouldContinue do
    --your os.pullEvent, etc. here. Have a button call quit()
end
shell.run('clear')
--you'll be returned to CraftOS

So, essentially, stop any loops then call shell.run (or term.clear, setCursorPos, etc)