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

Light Test Program Help

Started by zanenewberry, 18 June 2012 - 10:05 PM
zanenewberry #1
Posted 19 June 2012 - 12:05 AM
Hello, I'm creating a flashing light bar and i'm getting a lot of different error messages, can someone tell me what's wrong with this code?

x = 1
while x < 5 do
all = colors.combine(colors.magenta , colors.cyan , colors.light-grey , colors.purple , colors.orange , colors.lightBlue , colors.yellow , colors.pink)
rs.setBundledOutput("back", colors.magenta)
sleep(0.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.magenta)
rs.setBundledOutput("back", colors.cyan)
sleep(0.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.cyan)
rs.setBundledOutput("back", colors.light-grey)
sleep(0.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.light-grey)
rs.setBundledOutput("back", colors.purple)
sleep(0.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.purple)
rs.setBundledOutput("back", colors.orange)
sleep(0.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.orange)
rs.setBundledOutput("back", colors.lightBlue)
sleep(0.5)
rs.setBundledOutput("back", rs.getBundledOutput("back") - colors.lightBlue)
rs.setBundledOutput("back", all)
sleep(1)
rs.setBundledOutput("back", 0)
rs.setBundledOutput("back", all)
sleep(1)
rs.setBundledOutput("back", 0)
sleep(1)
end

Also can someone tell me how to continue this loop without the computer crashing? Thanks
archit #2
Posted 19 June 2012 - 12:14 AM
you never increment x, so it is always 0, and therefore will always be less than 5.

add:
x = x + 1

before the end statement
zanenewberry #3
Posted 19 June 2012 - 12:29 AM
Don't work.
MysticT #4
Posted 19 June 2012 - 12:33 AM
light-grey is not a color (in the colors api), lightGray is. Change that and it may work.
zanenewberry #5
Posted 19 June 2012 - 01:02 AM
Theres still an error

lighttestNWI:11: bad arguement: int expected, got nil
MysticT #6
Posted 19 June 2012 - 01:11 AM
This should work:

local all = colors.combine(colors.magenta , colors.cyan , colors.lightGray , colors.purple , colors.orange , colors.lightBlue , colors.yellow , colors.pink)

for i = 1, 5 do
  rs.setBundledOutput("back", colors.magenta)
  sleep(0.5)
  rs.setBundledOutput("back", colors.cyan)
  sleep(0.5)
  rs.setBundledOutput("back", colors.lightGray)
  sleep(0.5)
  rs.setBundledOutput("back", colors.purple)
  sleep(0.5)
  rs.setBundledOutput("back", colors.orange)
  sleep(0.5)
  rs.setBundledOutput("back", colors.lightBlue)
  sleep(0.5)
  rs.setBundledOutput("back", all)
  sleep(1)
  rs.setBundledOutput("back", 0)
  -- you should add a sleep here, cause it won't do anything like this
  rs.setBundledOutput("back", all)
  sleep(1)
  rs.setBundledOutput("back", 0)
  sleep(1)
end
zanenewberry #7
Posted 19 June 2012 - 01:39 AM
yeah it does, but i need it to continue in a loop without stopping
MysticT #8
Posted 19 June 2012 - 01:41 AM
Use a while loop:

local all = colors.combine(colors.magenta , colors.cyan , colors.lightGray , colors.purple , colors.orange , colors.lightBlue , colors.yellow , colors.pink)

while true do
  rs.setBundledOutput("back", colors.magenta)
  sleep(0.5)
  rs.setBundledOutput("back", colors.cyan)
  sleep(0.5)
  rs.setBundledOutput("back", colors.lightGray)
  sleep(0.5)
  rs.setBundledOutput("back", colors.purple)
  sleep(0.5)
  rs.setBundledOutput("back", colors.orange)
  sleep(0.5)
  rs.setBundledOutput("back", colors.lightBlue)
  sleep(0.5)
  rs.setBundledOutput("back", all)
  sleep(1)
  rs.setBundledOutput("back", 0)
  -- you should add a sleep here, cause it won't do anything like this
  rs.setBundledOutput("back", all)
  sleep(1)
  rs.setBundledOutput("back", 0)
  sleep(1)
end