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

"Attempt to call table" (Code for loading bar for project)

Started by Maj_GsL_Inc., 06 September 2016 - 08:39 PM
Maj_GsL_Inc. #1
Posted 06 September 2016 - 10:39 PM
Currently i'm trying to expand upon my code for a loading bar (by adding options such as color customization).

Currently i have it make a bar using the function Pr(x, y) x being the bar color and y being the outline box color

The issue is when i added in the box color option it give the "attempt to call table error"

here is the code

local function Cl()
term.clear()
term.setCursorPos(1, 1)
end
local function Cp(text)
    local x2,y2 = term.getCursorPos()
    local x,y = term.getSize()
    term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
    print(text)
end
local function Pr(x, y)
Cl()
startx = 4
endx = 48
ypos = 7
boxcolor = y
barcolor = x
stime = .5
	 paintutils.drawBox( 1,  1,  51,  19, colors(boxcolor))
for i=startx, endx do
	 paintutils.drawPixel(i, ypos, colors[barcolor])	 
	    sleep(stime)
end
end

Pr("red", "brown")
Cp("Done!")
sleep(2)
apemanzilla #2
Posted 06 September 2016 - 10:44 PM
You're trying to call colors (which is a table) on line 19. Change it from colors(boxcolor) to colors[boxcolor]
KingofGamesYami #3
Posted 06 September 2016 - 10:44 PM
This line:

         paintutils.drawBox( 1,  1,  51,  19, colors(boxcolor))

Should be this:


         paintutils.drawBox( 1,  1,  51,  19, colors[boxcolor])

Because colors is a table not a function (hence, attempt to call table).

In the future, please provide the complete error message, including the line number.
Maj_GsL_Inc. #4
Posted 07 September 2016 - 12:33 AM
Oh my gosh i'm a moron >_<, thanks for the help.

On notepad ++ and my screen it makes the [] seem very close to ()

Also just to avoid making another top i would like to make it so when it prints done it would auto change the text color into the inverted color of the bar color is that possible?
Edited on 06 September 2016 - 10:37 PM
ebernerd #5
Posted 07 September 2016 - 12:45 AM
You'd have to make a lookup table.


local inverse = {
  ["black"] = colours.white,
  ["grey"] = colours.white,
  --etc
}

term.setTextColour( inverse[ loadingBarColour ] )

Something like that. :)/>
Maj_GsL_Inc. #6
Posted 08 September 2016 - 01:25 AM
Cool thank you so much for your help :)/>