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

Missile Launch Terminal Program

Started by Drakkoran, 03 March 2012 - 02:12 AM
Drakkoran #1
Posted 03 March 2012 - 03:12 AM
This is actually my first time writing Lua. I've spent all day learning, going over the in game tutorial, reading stuff on here.


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

print("Missile Launch Terminal")
print("	1 - Commence Countdown & Launch")
print("	2 - Lock Terminal")
print("	3 - Terminal Reboot")
print("	4 - Terminal Shutdown")
while true do
event, param1, param2, param3, param4 = os.pullEvent()
if event == "char" and param1 == "1" then
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("30 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("20 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("10 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Commencing Launch")
redstone.setOutput("back", true)
sleep(2)
redstone.setOutput("back", false)
end
end


It works but how would I get it to auto-terminate and go back to the computer's main screen?
Advert #2
Posted 03 March 2012 - 03:16 AM
You can use the break keyword to break out of the loop; return should work as well (return will exit back to shell; whereas break will exit the loop)
Drakkoran #3
Posted 03 March 2012 - 03:35 AM
Thank you, much appreciated.

Is there by chance a way to set a program up to be the shell of the computer?

Better yet, like the Redworks Install Floppy set up where if the floppy is in the disk drive the computer will load the install program on startup?
Edited on 03 March 2012 - 02:41 AM
FuzzyPurp #4
Posted 03 March 2012 - 03:49 AM
name the program startup?
Thank you, much appreciated.

Is there by chance a way to set a program up to be the shell of the computer?

Better yet, like the Redworks Install Floppy set up where if the floppy is in the disk drive the computer will load the install program on startup?

Name the program startup?
Drakkoran #5
Posted 03 March 2012 - 03:51 AM
name the program startup?
Thank you, much appreciated.

Is there by chance a way to set a program up to be the shell of the computer?

Better yet, like the Redworks Install Floppy set up where if the floppy is in the disk drive the computer will load the install program on startup?

Name the program startup?

Oh, yes that would make sense. Thank you :unsure:/>/>
FuzzyPurp #6
Posted 03 March 2012 - 03:52 AM
You could also just have a startup program ask which program(s) to run or just have it shell.run("missile_launcher")
Sort of how i have the redworks floppy startup ask which operation to run, then it shell.runs whatever you choose.
A startup file is the foundation of your own custom shell :unsure:/>/>
Drakkoran #7
Posted 03 March 2012 - 03:58 AM
That would actually be better for how I plan on using the program. Thank you :unsure:/>/>
Drakkoran #8
Posted 03 March 2012 - 06:52 AM

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

print("Missile Launch Terminal")
print("	1 - Launch First Missile")
print("	2 - Launch Second Missile")
print("	3 - Launch Third Missile")
print("	4 - Launch All Missiles")
print("	5 - Lock Terminal")
print("	6 - Terminal Shutdown")
while true do
event, param1 = os.pullEvent()
if event == "char" and param1 == "1" then
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("30 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("20 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("10 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Commencing Launch")
redstone.setOutput("left", true)
sleep(2)
redstone.setOutput("left", false)
term.clear()
term.setCursorPos(1,1)
shell.run("MissileLaunch.lua")
	end

if event == "char" and param1 == "2" then
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("30 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("20 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("10 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Commencing Launch")
redstone.setOutput("back", true)
sleep(2)
redstone.setOutput("back", false)
term.clear()
term.setCursorPos(1,1)
shell.run("MissileLaunch.lua")
	end
if event == "char" and param1 == "3" then
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("30 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("20 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("10 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Commencing Launch")
redstone.setOutput("right", true)
sleep(2)
redstone.setOutput("right", false)
term.clear()
term.setCursorPos(1,1)
shell.run("MissileLaunch.lua")
	end
if event == "char" and param1 == "4" then
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("30 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("20 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Launch Commencing In T-Minus...")
print("10 Seconds")
sleep(10)
term.clear()
term.setCursorPos(1,1)
print("Commencing Launch")
redstone.setOutput("back", true)
redstone.setOutput("left", true)
redstone.setOutput("right", true)
sleep(2)
redstone.setOutput("back", false)
redstone.setOutput("left", false)
redstone.setOutput("right", false)
term.clear()
term.setCursorPos(1,1)
shell.run("MissileLaunch.lua")
	end
	if event == "char" and param1 = "5" then
term.clear()
term.setCursorPos(1,1)
print("Locking Terminal...")
sleep(2)
shell.run(startup)
end

if event == "char" and param1 = "6" then
term.clear()
term.setCursorPos(1,1)
print("Shutting Down...")
sleep(2)
shell.run(shutdown)
end
end

Okay, I've finished with it and now it's giving me a 'then' expected error, can anyone tell me why because I don't see it…

I know it's in the last two events on there because it was fine until i added those two in, if that helps at all.
Edited on 03 March 2012 - 05:56 AM
Liraal #9
Posted 03 March 2012 - 06:53 AM
I remember my first LUA program. It was a missile silo as well :unsure:/>/> Try working on toggling redstone, then you'll be able to fire salvos.
Drakkoran #10
Posted 03 March 2012 - 07:15 AM
Nevermind i found my problem :unsure:/>/>