Posted 08 May 2012 - 11:21 AM
                So we've just installed Tekkit on our SMP server and with that Computercraft, I have no prior experience with programming and I'm sure this isn't the most ideal solution to my problem, but I'm learning!
Anyway, I've written a tiny piece of software for me to control lights and my nuclear reactor (what a combo, eh?) but I will expand it once I get a better understanding of computercraft. My code is below, when I fire it up and select 'lights' all works dandy, but if I exit from that submeny and type in 'reactor' I just get '50' printed on the commandline and the program exits.
What could be causing this?
                
            Anyway, I've written a tiny piece of software for me to control lights and my nuclear reactor (what a combo, eh?) but I will expand it once I get a better understanding of computercraft. My code is below, when I fire it up and select 'lights' all works dandy, but if I exit from that submeny and type in 'reactor' I just get '50' printed on the commandline and the program exits.
What could be causing this?
Spoiler
term.clear()
term.setCursorPos(1,1)
x = 0.1
function main()
	print(" ---------------------------------")
	print("| What would you like to control? |")
	print(" ---------------------------------")
	print("|								 |")
	print("| lights						  |")
	print("| reactor						 |")
	print("|								 |")
	print(" ---------------------------------")
	input = read()
	lights = "lights"
	reactor = "reactor"
end
function lightOn()
	curColors = rs.getBundledInput("back")
	rs.setBundledOutput("back", colors.combine(curColors, colors.white))
	sleep(x)
	light()
end
function lightOff()
	rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.white)
	sleep(x)
	light()
end
function light()
	shell.run("clear")
	print(" ----------------------------------------------")
	print("| Would you like to turn the lights on or off? |")
	print(" ----------------------------------------------")
	print("|											  |")
	print("| on										   |")
	print("| off										  |")
	print("| exit										 |")
	print("|											  |")
	print(" ----------------------------------------------")
	input = read()
	on = "on"
	off = "off"
	exit = "exit"
	if input == on then
		lightOn()
	end
	if input == off then
		lightOff()
	end
	if input == exit then
		shell.run("clear")
	end
end
function reactorOn()
	curColors = rs.getBundledInput("back")
	rs.setBundledOutput("back", colors.combine(curColors, colors.yellow))
	sleep(x)
	reactor()
end
function reactorOff()
	rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.yellow)
	sleep(x)
	reactor()
end
function reactor()
	shell.run("clear")
	print(" -----------------------------------------------")
	print("| Would you like to turn the reactor on or off? |")
	print(" -----------------------------------------------")
	print("|											   |")
	print("| on											|")
	print("| off										   |")
	print("| exit										  |")
	print("|											   |")
	print(" -----------------------------------------------")
	input = read()
	on = "on"
	off = "off"
	exit = "exit"
	if input == on then
		reactorOn()
	end
	if input == off then
		reactorOff()
	end
	if input == exit then
		shell.run("clear")
	end
end
while true do
	main()
	if input == "lights" then
		light()
	end
	if input == "reactor" then
		reactor()
	end
end