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

Purely Aesthetic Exit Program

Started by Mr. Fang, 20 September 2012 - 02:50 PM
Mr. Fang #1
Posted 20 September 2012 - 04:50 PM
This is a PURELY Aesthetic Exit program that I designed for a Home Computer System within ComputerCraft.
For this to work I suggest that your "Main Menu" contain several programs so when you exit one of those programs, you have a place to go back to.

First, find the program you want to add the "Exit" option to.
Then add this code to it's ending:

print("Type 'Exit' to Return To The Menu")
shell.run("Exit")  --Runs your *New* Exit program

3rd, Create a file named "Exit" by typing into your terminal "edit Exit"

Then type this into your exit file…plz be sure to read the comments throughout this…they contain helpful info and more setup.


term.clear()
term.setCursorPos(1,1)
print("Exiting to Menu")
sleep(1)
term.setCursorPos(16,1)
print(".")
sleep(1)
term.setCursorPos(17,1)
print(".")
sleep(1)
term.setCursorPos(18,1)
print(".")
sleep(3)
shell.run("startup") --The name ofyour menu program


Please bear in mind, your menu program might need the code to erase the screen before it starts:

term.clear()
term.setCursorPos(1,1)

Thank You for viewing, any comments/bugs/fixes you can place in the comment section below.
This code hasn't been tested yet, why don't you be the first?
MysticT #2
Posted 20 September 2012 - 05:43 PM
It's a really bad idea to re-run a program to "exit", it will overflow the stack after some time.
Also, it's better to have the code inside your actual program than running another one just to do it.
Mr. Fang #3
Posted 20 September 2012 - 10:52 PM
FYI this was only for fun and would be useful if you didn't want to write all of this into all of your programs.
MysticT #4
Posted 20 September 2012 - 11:06 PM
I know, you can do it however you want. The problem is using shell.run to run the program you are already running, it can crash the computer. You should make it really exit, not just look like it exits. Also, when the program actually exits, the previous is still running.