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

program opens program, then returns

Started by Thomas9666, 22 May 2012 - 06:17 PM
Thomas9666 #1
Posted 22 May 2012 - 08:17 PM
How would I code that a startup program asks which option you want, then opens that program( i know this bit) but after that how would I return to the startup where I had left it?
cant_delete_account #2
Posted 22 May 2012 - 08:24 PM
It automatically returns where it was.
MysticT #3
Posted 22 May 2012 - 08:25 PM
When the program you run with shell.run() exits, your program continues where it was. So if you have these two programs:
Program hello:

print("Hello World!")
Your program:

print("Program starting...")
shell.run("hello")
print("Hello to you")
It would do the first print, then run the hello program that prints "Hello World!", and then it would do the last print("Hello to you").
Also, shell.run returns a boolean that indicates if the program ended correctly and any values returned by the program.
Thomas9666 #4
Posted 22 May 2012 - 09:29 PM
Sorry, I forgot that both of the things I wanted were separate programs, sorry

But how would I repeat a script?
MysticT #5
Posted 22 May 2012 - 11:18 PM
If you want to make a program repeat some part of the code (even the whole program), you can use a loop. There's diferent types of loops depending on how much times you need to do it. The most common is:

while true do
  -- your code
end
That makes an infinite loop, so if you put your program's code inside it will run forever (until the computer shuts down or the program is terminated).
Thomas9666 #6
Posted 22 May 2012 - 11:43 PM
cool thanks:)