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

Attempt to preform Arithmetic __add error

Started by SNWLeader, 14 October 2012 - 03:08 PM
SNWLeader #1
Posted 14 October 2012 - 05:08 PM
I am trying to get a system to work through a bundle output to turn on a section of lights when done, but when I try to get through the arithmetic part the darn thing does not work.
I am trying to do this


WH = 1
OR = 2
MA = 4
LB = 8


finalinput = WH + OR + MA + LB

rs.setBundledOutput("back", finalinput)

if you need the whole code comment soon.
Doyle3694 #2
Posted 14 October 2012 - 05:12 PM
whole code would be nice
SNWLeader #3
Posted 14 October 2012 - 05:18 PM
whole code would be nice

here it is. This is just a test experiment on me making a very long working system through one wire.

repeat
term.clear()
term.setCursorPos(1,1)
print("Colors: white, orange, magenta, lightblue")
print("When done type 'done' and press enter key.")
write("Lighting Colors:  ")
input = read()
if input == "white" then
WH = 1
elseif input == "orange" then
OR = 2
elseif input == "magenta" then
MA = 4
elseif input == "lightblue" then
LB = 8
else
print("Sorry no such color")
end
until input == "done"
term.clear()
term.setCursorPos(1,1)
print("Turning On input")
textutils.slowPrint(".......")
sleep(1)
finalinput = WH + OR + MA + LB
rs.setBundledOutput("back", finalinput )
ardera #4
Posted 14 October 2012 - 05:33 PM
The problem is, if you enter a color, one of the four variables gets declared, the others NOT.

So your code has to be something like that:

repeat
term.clear()
term.setCursorPos(1,1)
print("Colors: white, orange, magenta, lightblue")
print("When done type 'done' and press enter key.")
write("Lighting Colors:  ")
input = read()
choosen=0
if input == "white" then
  choosen=1
elseif input == "orange" then
  choosen=2
elseif input == "magenta" then
  choosen=4
elseif input == "lightblue" then
  choosen=8
else
  print("Sorry no such color")
end
until input == "done"
term.clear()
term.setCursorPos(1,1)
print("Turning On input")
textutils.slowPrint(".......")
sleep(1)
finalinput = choosen
rs.setBundledOutput("back", finalinput )
SNWLeader #5
Posted 14 October 2012 - 06:14 PM
The only thing is I am trying to get it were I type in the colors I want on then I type enter so the lights I typed in turn on.
Doyle3694 #6
Posted 14 October 2012 - 06:18 PM
Just add:

local WH = 0
local OR = 0
local MA = 0
local LB = 0

at the top
SNWLeader #7
Posted 14 October 2012 - 06:31 PM
I fixed what I was doing. I did a little recoding. :)/>/>
Doyle3694 #8
Posted 14 October 2012 - 06:34 PM
Wanna post your code? interested to see how you did it :)/>/>