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

(colors:36 Expected Number, Number) need Help !

Started by Gladox114, 17 July 2018 - 08:22 PM
Gladox114 #1
Posted 17 July 2018 - 10:22 PM
I want to use Bundled cables from projectred and toggle the lights or Sprinklers with a command.

https://pastebin.com/yAGi3TXx

What did i made wrong?

The code is not polished and is a little mixed up.


-----Functions-----
local function AddOutput(sSide,...)
local c = colors.combine(rs.getBundledOutput(sSide),...)
  rs.setBundledOutput(sSide,c)
end
local function RemoveOutput(sSide,...)
  local c = colors.subtract(rs.getBundledOutput(sSide),...)
  rs.setBundledOutput(sSide,c)
end
-------Table---------
Table = {}
Table[1]= {["on"] = false,["name"] = "Purple Lamp",["color"] = colors.purple}
Table[2] = {["on"] = false,["name"] = "Green Lamp",["color"] = colors.red}
Table[101] = {["on"] = false,["name"] = "Sprinkler 1",["color"] = colors.lime}
Table[102] = {["on"] = false,["name"] = "Sprinkler 2",["color"] = colors.yellow}
Table[103] = {["on"] = false,["name"] = "Sprinkler 3",["color"] = colors.brown}
Table[104] = {["on"] = false,["name"] = "Sprinkler 4",["color"] = colors.white}
all = colors.combine(colors.red,colors.yellow,colors.lime,colors.brown,colors.purple,colors.white)
rs.setBundledOutput("top",all)
----------------------
local function showtable()
term.setCursorPos(1,1)
term.clear()
for i , v in pairs(Table) do
c = Table[i]["on"]
local s = "off"
if c == true then
    s = "on"
else
  s = "off"
end

l = Table[i]["name"]
io.write(l)
Cursorx,CursorY = term.getCursorPos()
term.setCursorPos(14,CursorY)
io.write(s.."\n")
end
term.setCursorBlink(true)
io.write("> ")
end
---------------------------
function test(thing)
local t = string.lower(thing)
if string.find(t,"pu") then
return 1
elseif string.find(t,"gr") then
return 2
elseif string.find(t,"1") then
return 101
elseif string.find(t,"2") then
return 102
elseif string.find(t,"3") then
return 103
elseif string.find(t,"4") then
return 104
else
return false
end
end
---------------------------
while true do
showtable()
read = test(io.read())
if read then
tcolor = Table[read]["color"]
    if colors.test("top",tcolor) == true then
    Table[read]["on"] = true
    RemoveOutput("top",tcolor)
  elseif colors.test("top",tcolor) == false then
    Table[read]["on"] = false
    AddOutput("top",tcolor)
  end
end
read = false
end
Bomb Bloke #2
Posted 18 July 2018 - 12:12 AM
Your table uses numeric indexes, but io.read() returns strings: so Table[read]["color"]
will always be nil. Try "tonumber(io.read())".
Gladox114 #3
Posted 18 July 2018 - 03:07 AM
Thanks! I will try it when i wake up ^^
Gladox114 #4
Posted 18 July 2018 - 12:12 PM
Doesn't work for me. but it is already a number and not a string because the test() function returns from the read a number or a false. If i write gr or Green light it returns 2 and so on.


And yes i tested it with tonumber but the problem is the same.

Colors:36: Expected number , number
what does it mean?
Edited on 18 July 2018 - 10:14 AM
Bomb Bloke #5
Posted 18 July 2018 - 12:26 PM
Well, this here is the line throwing the error, so it means you're calling colours.test() with something other than two numbers.

And indeed, your script is calling it with a string and a number instead, as though it were rs.testBundledInput()!
Lupus590 #6
Posted 18 July 2018 - 12:27 PM
Colors:36: Expected number , number
what does it mean?

toNumber returns nil when it can't convert

the error message says that a function called on line 36 expected two arguments both of the type number but got something else. you may want to check that what is being converted to a number is convertable.
Gladox114 #7
Posted 19 July 2018 - 12:40 AM
Well, this here is the line throwing the error, so it means you're calling colours.test() with something other than two numbers.

And indeed, your script is calling it with a string and a number instead, as though it were rs.testBundledInput()!

Thanks i was really stuipid because i mistake with my top = rs.getBundledOutput("top") and with "top"


https://pastebin.com/6gtCjVGt

Now it works great ! Thanks !!