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

colors.combine and colors.subtract not doing their jobs?

Started by Tassyr, 08 April 2013 - 07:49 AM
Tassyr #1
Posted 08 April 2013 - 09:49 AM
So I'm trying to set up a system where by detault the computer keeps output steady on six redstone colors (Green, Red, Gray, White, Blue and Black.) and one that keeps off (Cyan.) Each of the six "on" colors can be toggled off for 10 seconds, then will reactivate. THAT part I have working just fine.

The one that doesn't work fine is the seventh option- the plan is to leave the Six "on" colors on and just activate the Cyan one. However every time it activates, the Cyan is the ONLY one active- the others deactivate. I'm going in circles. Anyone got an idea what I did wrong?

Spoiler



term.clear()
term.setCursorPos(1,1)
while true do
c = colors.combine(colors.green, colors.gray, colors.red, colors.white, colors.black, colors.blue)
rs.setBundledOutput("right",c)
term.clear()
term.setCursorPos(1,1)
print("**************************************************")
print("*****  Vault-Tek  Radiological Research Lab  *****")
print("**************************************************")
i = 4
repeat
term.setCursorPos(1,i)
print("*****                                        *****")
i = 1 + i
until i == 16
print("**************************************************")
print("*****                                        *****")
print("**************************************************")
term.setCursorPos(7,6)
print("[1] Specimen 001 'Creeper'")
term.setCursorPos(7,7)
print("[2] Specimen 002 'Skeleton'")
term.setCursorPos(7,8)
print("[3] Specimen 003 'Zombie'")
term.setCursorPos(7,9)
print("[4] Specimen 004 'Slime'")
term.setCursorPos(7,10)
print("[5] Specimen 005 'Cave Spider'")
term.setCursorPos(7,11)
print("[6] Specimen 006 'Spider'")
term.setCursorPos(7,13)
print("[7] EMERGENCY SPECIMEN PURGE SYSTEM")
term.setCursorPos(6,17)
print(" Enter Selection: ")
term.setCursorPos(24,17)
input = read()
if input == "7" then
rs.setOutput("top", true)
c = colors.combine(colors.cyan)
rs.setBundledOutput("right",c)
sleep (15)
rs.setOutput("top", false)
c = colors.subtract(colors.cyan)
rs.setBundledOutput("right",c)
end
if input == "1" then
c = colors.subtract(colors.green)
rs.setBundledOutput("right",c)
sleep (12)
end
if input == "2" then
c = colors.subtract(colors.red)
rs.setBundledOutput("right",c)
sleep (10)
end
if input == "3" then
c = colors.subtract(colors.gray)
rs.setBundledOutput("right",c)
sleep (10)
end
if input == "4" then
c = colors.subtract(colors.white)
rs.setBundledOutput("right",c)
sleep (10)
end 
if input == "5" then
c = colors.subtract(colors.blue)
rs.setBundledOutput("right",c)
sleep (10)
end 
if input == "6" then
c = colors.subtract(colors.black)
rs.setBundledOutput("right",c)
sleep (10)
end 
end

theoriginalbit #2
Posted 08 April 2013 - 09:51 AM
fix the code spoiler please.

EDIT: nvm, you just did it.
Edited on 08 April 2013 - 07:52 AM
LBPHacker #3
Posted 08 April 2013 - 09:51 AM
The BB interpreter messed it up. Pastebin please.

EDIT: Yay ninja'd…
theoriginalbit #4
Posted 08 April 2013 - 09:55 AM
one of your problems is colors.combine and colors.subtract aren't magic, they don't look for what the bundled output is already, they combine the colours that you supply, you are only supplying one colour. make it something like

c = colors.combine(colors.cyan, rs.getBundledInput("right"))
rs.setBundledOutput("right",c)

EDIT: Also use elseif's for your checking of what the user entered.
Edited on 08 April 2013 - 07:57 AM
Tassyr #5
Posted 08 April 2013 - 10:19 AM
oh for the love of… I'm an idiot. I forgot I meant to put


c = colors.combine(c, colors.cyan)

But your code works better. x.x

Also is there some colossal problem with using if instead of elseif?
PixelToast #6
Posted 08 April 2013 - 10:22 AM
Also is there some colossal problem with using if instead of elseif?
yes, it makes code look ugly and inneficent
theoriginalbit #7
Posted 08 April 2013 - 04:10 PM
Also is there some colossal problem with using if instead of elseif?
yes, it makes code look ugly and inneficent
Not only that, but it does use extra CPU cycles to evaluate each conditional, as opposed to just 'skipping' them all.
PixelToast #8
Posted 09 April 2013 - 03:13 AM
if anyone cares about a couple more CPU cycles from simple if statements they sould just go write in lua bytecode to achieve maximum efficiency
LordIkol #9
Posted 09 April 2013 - 04:08 AM
if anyone cares about a couple more CPU cycles from simple if statements they sould just go write in lua bytecode to achieve maximum efficiency

But using elseif instead of another if is a quick win of efficency
writing bytecode is more efficient but not worth the work it takes :P/>