Posted 07 April 2013 - 10:51 AM
Hey guys,
I am working on a disco room for my server, and this is the code I have so far. This was all working fine until I added the flashHalf() function, which tells me it might have to do with that. The error I get is:
startup:9: attempt to perform arithmetic __add on nil and nil
The code gets kind of messed up on here. Line 9 is where allColors is defined.
Here is the code:
Anyone know why it stopped working?
Thanks!
I am working on a disco room for my server, and this is the code I have so far. This was all working fine until I added the flashHalf() function, which tells me it might have to do with that. The error I get is:
startup:9: attempt to perform arithmetic __add on nil and nil
The code gets kind of messed up on here. Line 9 is where allColors is defined.
Here is the code:
side = "right"
local lime = colors.lime
local red = colors.red
local blue = colors.blue
local magenta = colors.magenta
local yellow = colors.yellow
allColors = lime + red + blue + magenta + yellow
function colorsOff()
rs.setBundledOutput(side, 0)
end
function colorsOn()
rs.setBundledOutput(side, allColors)
end
function limeOn()
rs.setBundledOutput(side, lime)
end
function redOn()
rs.setBundledOutput(side, red)
end
function yellowOn()
rs.setBundledOutput(side, yellow)
end
function blueOn()
rs.setBundledOutput(side, blue)
end
function magentaOn()
rs.setBundledOutput(side, magenta)
end
function slowCycle()
for i = 1, 4 do
limeOn()
sleep(1)
colorsOff()
redOn()
sleep(1)
colorsOff()
blueOn()
sleep(1)
colorsOff()
yellowOn()
sleep(1)
colorsOff()
magentaOn()
sleep(1)
colorsOff()
end
end
function fastCycle()
for i = 1, 4 do
limeOn()
sleep(.5)
colorsOff()
redOn()
sleep(.5)
colorsOff()
blueOn()
sleep(.5)
colorsOff()
yellowOn()
sleep(.5)
colorsOff()
magentaOn()
sleep(.5)
colorsOff()
end
end
function superFastCycle()
for i = 1, 4 do
limeOn()
sleep(.1)
colorsOff()
redOn()
sleep(.1)
colorsOff()
blueOn()
sleep(.1)
colorsOff()
yellowOn()
sleep(.1)
colorsOff()
magentaOn()
sleep(.1)
colorsOff()
end
end
function flashHalf()
for i = 1, 4 do
colors = {lime, red, yellow, blue, magenta}
numLeft = 4
rand1 = math.random(0, numLeft)
newColor1 = colors[rand1]
table.remove(colors, rand1)
numLeft = numLeft - 1
rand3 = math.random(0, numLeft)
newColor3 = colors[rand3]
table.remove(colors, rand3)
numLeft = numLeft - 1
rand2 = math.random(0, numLeft)
newColor2 = colors[rand2]
table.remove(colors, rand2)
numLeft = numLeft - 1
rand4 = math.random(0, numLeft)
newColor4 = colors[rand4]
table.remove(colors, rand4)
numLeft = numLeft - 1
rand5 = math.random(0, numLeft)
newColor5 = colors[rand5]
table.remove(colors, rand5)
numLeft = numLeft - 1
rs.setBundledOutput(side, newColor1 + newColor2 + newColor3)
sleep(.5)
colorsOff()
rs.setBundledOutput(side, newColor4 + newColor5)
sleep(.5)
colorsOff()
end
end
function flashAll()
for i = 1, 4 do
colorsOn()
sleep(.5)
colorsOff()
sleep(.5)
end
end
while true do
flashHalf()
end
Anyone know why it stopped working?
Thanks!