Posted 30 November 2012 - 02:47 PM
I'm trying to make a computer that controls some RedPower2 lamps with bundled cable when I start the program everything works fine and the lamps turn on but when I close the computer screen it stops and gives this error: bit:40: bad argument: double expected, got nil.
Here is my code:
If anyone can see what I did wrong please let me know.
Here is my code:
local names = {"Floor 1", "Floor 2", "Floor 3", "Floor 4"}
local keycolors = {colors.orange, colors.white, colors.yellow, colors.black}
local curcolors = 0
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
while 1
do
term.clear()
term.setCursorPos(1, 1)
for cnt = 1, tablelength(keycolors) do
local status = "Off"
if colors.test(curcolors, keycolors[cnt]) then
status = "On"
end
print("[" .. cnt .. "] " .. names[cnt] .. ": " .. status)
end
evt, one, two, three = os.pullEvent()
if evt == "key" then
if (one - 1) <= tablelength(keycolors) then
if colors.test(curcolors, keycolors[one - 1]) then
colors.subtract(curcolors, keycolors[(one - 1)])
else
curcolors = colors.combine(keycolors[(one - 1)], curcolors)
end
end
end
rs.setBundledOutput("bottom", curcolors)
sleep(0.3)
end
If anyone can see what I did wrong please let me know.