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

window:179:bad argument: string expected, got nil

Started by DiNuzz__, 15 August 2016 - 08:49 PM
DiNuzz__ #1
Posted 15 August 2016 - 10:49 PM
I tried to do something like a stupid GUI for CC and while debugging I got this error:

window:179: bad argument: string expected, got nil
Press any key to continue
I press a random key and then the computer shuts down :-(

PROGRAM: http://pastebin.com/BNEDzDMg
CC Version: 1.79

Please, don't tell me it's a stupid project, I already know.
Thank you :)/>
Emma #2
Posted 16 August 2016 - 02:31 AM
You store the color information as string literals, then try to set the background/text color with said string literal. Do one of the following:

local desktopbar = {
  "                                                  ",
  colors.black,
  colors.white
}
Or you could do something like this:

local desktopbar = {
  "                                                  ",
  "black",
  "white"
}
-- So use the code you are already using

-- But when you set the colors, do this
term.setBackgroundColor( colors[ name[2] ] )
term.setTextColor( colors[ name[3] ] )
DiNuzz__ #3
Posted 16 August 2016 - 11:57 AM
You store the color information as string literals, then try to set the background/text color with said string literal. Do one of the following:

local desktopbar = {
  "												  ",
  colors.black,
  colors.white
}
Or you could do something like this:

local desktopbar = {
  "												  ",
  "black",
  "white"
}
-- So use the code you are already using

-- But when you set the colors, do this
term.setBackgroundColor( colors[ name[2] ] )
term.setTextColor( colors[ name[3] ] )
Oh, thank you!
I didn't remember that, the last time I used computercraft was back in 2014!