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

I do not know how to fix this error ;(

Started by Dahleytje, 29 November 2012 - 02:32 AM
Dahleytje #1
Posted 29 November 2012 - 03:32 AM
Hi, I've just started with ComputerCraft and I'm still learning the basics.

I am working creating an alarm system which enables a howler alarm and makes all the lights flash in my house.
It worked when I used it with normal redstone alloy wires. But now I'm using bundled cables and I can't seem to get it to work:


term.clear()
term.setCursorPos(1,1)
print("1 = on")
print("2 = on")
input = read()
answer1 = "1"
if input == answer1 then
term.clear()
c = colors.subtract( c, colors.orange )
rs.setBundledOutput("top", colors.orange )
sleep(1)
rs.setBundledOutput("top", c )
shell.run("system")
end

Now the problem is: it gives me the following error once i've typed 1

bit:40: bad argument: double expected, got nil


Also how do I make it loop? turn on one second, turn off one second and loop that

Thanks in advance!
Kingdaro #2
Posted 29 November 2012 - 03:49 AM
It's giving the error because c doesn't exist before the script defines it. c should be the current RS bundle, yes? Also, by setting the bundledOutput to orange, it's going to be just orange and cancel out all other colors.


term.clear()
term.setCursorPos(1,1)
print("1 = on")
print("2 = on")
input = read()
answer1 = "1"
if input == answer1 then
term.clear()
rs.setBundledOutput("top", colors.combine(rs.getBundledOutput("top"), colors.orange) ) -- add the color orange
sleep(1)
rs.setBundledOutput("top", colors.subtract(rs.getBundledOutput("top"), colors.orange) ) -- take away orange
shell.run("system")
end

Not really experienced with bundles myself, so if i made a mistake here, someone please correct me. :D/>
Dahleytje #3
Posted 29 November 2012 - 04:06 AM
I managed to do it thanks to you. I really appreciate it!!

Another little question, is there a short way to loop it?
And how do I break the loop?

Thanks!
Kingdaro #4
Posted 29 November 2012 - 04:18 AM
To loop, just put whatever code you wanna loop in while true do … end, and you use break to break out of it.

while true do
  -- your code

  if some_condition == true then
    break -- this breaks out of the loop if some_condition is true
  end
end