Jump to content




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

computer help lua

6 replies to this topic

#1 Gladox114

  • Members
  • 6 posts

Posted 17 July 2018 - 09: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


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 17 July 2018 - 11:12 PM

Your table uses numeric indexes, but io.read() returns strings: so Table[read]["color"]
will always be nil. Try "tonumber(io.read())".

#3 Gladox114

  • Members
  • 6 posts

Posted 18 July 2018 - 02:07 AM

Thanks! I will try it when i wake up ^^

#4 Gladox114

  • Members
  • 6 posts

Posted 18 July 2018 - 11:12 AM

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 by Gladox114, 18 July 2018 - 11:14 AM.


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 18 July 2018 - 11:26 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()!

#6 Lupus590

  • Members
  • 1,975 posts
  • LocationUK

Posted 18 July 2018 - 11:27 AM

View PostGladox114, on 18 July 2018 - 11:12 AM, said:

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.

#7 Gladox114

  • Members
  • 6 posts

Posted 18 July 2018 - 11:40 PM

View PostBomb Bloke, on 18 July 2018 - 11:26 AM, said:

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 !!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users