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

Returns number, no error message

Started by Ojeu, 08 May 2012 - 09:21 AM
Ojeu #1
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?

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  
libraryaddict #2
Posted 08 May 2012 - 02:17 PM
Restart the server for the number error message.
And I think you are handling this wrong.

rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.white)
Ojeu #3
Posted 08 May 2012 - 02:39 PM
Restart the server for the number error message.
And I think you are handling this wrong.

rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.white)
I am working on the program in singleplayer, but it did indeed help to restart the game.
Oh, I am? How would you do it? :)/>/>
And thanks!
Luanub #4
Posted 08 May 2012 - 10:23 PM
The cleanest way to handle bundled cables is like this..


curColors = colors.combine(curColors) -- add to start of code

curColors = colors.combine( curColors, colors.white) -- adds white to the colors
rs.setBundledOutput(side, curColors) -- turns on white

curColors = colors.combine(curColors, colors.red) -- add red to the colors
rs.setBundledOutput(side, curColors) -- turns on red with white still on

curColors = colors.subtract(curColors, colors.white) -- remove white
rs.setBundledOutput(side, curColors) -- turns off white leaving red on