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

Bundled Output Help!

Started by rawritsdan, 15 June 2012 - 09:43 PM
rawritsdan #1
Posted 15 June 2012 - 11:43 PM
Hi guys, im new to the whole redpower scene and im having some trouble with my program. I want to be able to enable and disable a specific color to activate my circuit, but the way I have followed has led me to a 'BIT:40' error.
Heres my code:

term.clear()
term.setCursorPos(17,1)
print "Light Control"
term.setCursorPos(1,2)
print ""
print "1. Turn On Dancefloor"
print "2. Turn Off Dancefloor"
print "3. Turn On Bar Lights"
print "4. Turn Off Bar Lights"
input = read()
if input == "1" then
a = colors.combine(a,colors.blue)
rs.setBundledOutput("back",a)
print "Dancefloor Activated"
sleep(3)
shell.run("startup")
end
if input == "2" then
[color=#ff0000]b= colors.subtract(x,colors.)
rs.setBundledOutput("back",:)/>/>[/color]
print "Dancefloor Is Now De-Activated"
sleep(3)
shell.run("startup")
end
if input == "3" then
c = colors.combine(c,colors.lime)
rs.setBundledOutput("back",c)
print "Bar Lights Are Now Turned On"
sleep(3)
shell.run("startup")
end
if input == "4" then
[color=#ff0000]d = colors.subtract(d,colors.lime)
rs.setBundledOutput("back",d)[/color]
print "Bar Lights Are Now Turned Off"
sleep(3)
shell.run("startup")
else
print "Please Choose Another Option!"
sleep(2)
shell.run("startup")
end

I can Activate the bundled wire but not disable the various colors,
thanks Dan :(/>/>
Pinkishu #2
Posted 16 June 2012 - 11:32 AM
First, wrong forums
second, I don't ever see you defining d?
rawritsdan #3
Posted 19 June 2012 - 10:56 AM
First, wrong forums
second, I don't ever see you defining d?
"d = colors.subtract(d,colors.lime)" that is defining D isnt it?
Well anywhere you could suggest I could Re-Post?
thanks
Cloudy #4
Posted 19 June 2012 - 11:54 AM
Here is your fixed code:

while true do 
    term.clear()
    term.setCursorPos(17,1)
    print "Light Control"
    term.setCursorPos(1,2)
    print ""
    print "1. Turn On Dancefloor"
    print "2. Turn Off Dancefloor"
    print "3. Turn On Bar Lights"
    print "4. Turn Off Bar Lights"
    input = read()
    local cur = rs.getBundledOutput("back")
    if input == "1" then
        a = colors.combine(cur,colors.blue)
        rs.setBundledOutput("back",a)
        print "Dancefloor Activated"
        sleep(3)
    elseif input == "2" then
        b=colors.subtract(cur,colors.blue)
        rs.setBundledOutput("back",:(/>/>
        print "Dancefloor Is Now De-Activated"
        sleep(3)
    elseif input == "3" then
        c = colors.combine(cur,colors.lime)
        rs.setBundledOutput("back",c)
        print "Bar Lights Are Now Turned On"
        sleep(3)
    elseif input == "4" then
        d = colors.subtract(cur,colors.lime)
        rs.setBundledOutput("back",d)
        print "Bar Lights Are Now Turned Off"
        sleep(3)
    else
        print "Please Choose Another Option!"
        sleep(2)
    end
end

Basically, you were trying to subtract a colour from a nil value - you didn't even find out what the current output was in your code. I've now set the current output to be in a variable called "cur". I also put it all into a while true loop - you were just calling the same program again, which eventually would mean the program would break down.
Pinkishu #5
Posted 19 June 2012 - 12:42 PM
Ah didn't see it cause of the weird color tags xD
rawritsdan #6
Posted 19 June 2012 - 01:59 PM
Here is your fixed code:

while true do
	term.clear()
	term.setCursorPos(17,1)
	print "Light Control"
	term.setCursorPos(1,2)
	print ""
	print "1. Turn On Dancefloor"
	print "2. Turn Off Dancefloor"
	print "3. Turn On Bar Lights"
	print "4. Turn Off Bar Lights"
	input = read()
	local cur = rs.getBundledOutput("back")
	if input == "1" then
		a = colors.combine(cur,colors.blue)
		rs.setBundledOutput("back",a)
		print "Dancefloor Activated"
		sleep(3)
	elseif input == "2" then
		b=colors.subtract(cur,colors.blue)
		rs.setBundledOutput("back",-_-/>/>
		print "Dancefloor Is Now De-Activated"
		sleep(3)
	elseif input == "3" then
		c = colors.combine(cur,colors.lime)
		rs.setBundledOutput("back",c)
		print "Bar Lights Are Now Turned On"
		sleep(3)
	elseif input == "4" then
		d = colors.subtract(cur,colors.lime)
		rs.setBundledOutput("back",d)
		print "Bar Lights Are Now Turned Off"
		sleep(3)
	else
		print "Please Choose Another Option!"
		sleep(2)
	end
end

Basically, you were trying to subtract a colour from a nil value - you didn't even find out what the current output was in your code. I've now set the current output to be in a variable called "cur". I also put it all into a while true loop - you were just calling the same program again, which eventually would mean the program would break down.

Many thanks cloudy! As you can tell I am a bit of a noob when it comes to scripting in LUA for computercraft, also thanks for cleaning it up :)/>/>
haha yes pinkishu its a bit scruffy my code :(/>/>
thanks Dan -_-/>/>
rawritsdan #7
Posted 19 June 2012 - 02:21 PM
Tested the code, worked like a charm with the tinyest tweak, line 20 has to be a lower case 'b' to work. Other than that 100% great, thanks alot guys! :(/>/>
Dan