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

Errors (Window:!50 & Window:48/88) (Stuck on Window:!50 Loop)

Started by Maj_GsL_Inc., 07 September 2016 - 11:51 PM
Maj_GsL_Inc. #1
Posted 08 September 2016 - 01:51 AM
So i'm working on a program that makes a loading bar on the screen.

At the moment i have made it work to the point i wanted to add a text color inversion system (it would invert the text color to a set inverse of the bar color)

I did this using a table and term.setTextColor, when i went to execute the program it flashed Window:48 (or Window:88, couldn't tell as it flashed on for only a second), then proceeded to shut down and reboot and give me "Window:150 bad argument, string expected, got nil" and prompted to press any key to continue (which i did) however this just caused the terminal to reboot and prompt the same message. The only lines changed from the last working rendition of the code are [1-18 & 51].

Code:

local inverse = {
["white"] = colors.black,
["orange"] = colors.red,
["magenta"] = colors.cyan,
["lightBlue"] = colors.black,
["yellow"] = colors.blue,
["lime"] = colors.black,
["pink"] = colors.yellow,
["gray"] = colors.white,
["lightGray"] = colors.black,
["cyan"] = colors.black,
["purple"] = colors.black,
["blue"] = colors.yellow,
["brown"] = colors.white,
["green"] = colors.black,
["red"] = colors.black,
["black"] = colors.white
}
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, z, w)
Cl()
startx = 4
endx = 48
ypos = 7
boxcolor = y
barcolor = x
stime = z
bckcolor = w
	 term.setBackgroundColor(colors[bckcolor])
	 paintutils.drawBox( 1,  1,  51,  19, colors[boxcolor])
for i=startx, endx do
	 paintutils.drawPixel(i, ypos, colors[barcolor])	 
	    sleep(stime)
end
end

term.setTextColor( inverse[barcolor] )
Pr("blue", "lime", .2, "grey")
Cp("Done!")
sleep(2)
KingofGamesYami #2
Posted 08 September 2016 - 02:05 AM
colors[ "grey" ] is nil
colours[ "grey" ] is not nil, neither is colors[ "gray" ]
Edited on 08 September 2016 - 12:06 AM
Maj_GsL_Inc. #3
Posted 08 September 2016 - 06:03 PM
What the heck does that even mean can you explain a bit more?
KingofGamesYami #4
Posted 08 September 2016 - 06:24 PM
You do this:


Pr("blue", "lime", .2, "grey")

Which ends up doing this:

         term.setBackgroundColor(colors["grey"]) --# was bckcolor

Which is the same as:

term.setBackgroundColor( nil )

The window API doesn't check for a valid color, which leads to problems when the paintutils API tries to use term.write.
Dog #5
Posted 08 September 2016 - 11:26 PM
To build a little on KingofGamesYami's answer - grey with an 'e' and gray with an 'a' are not considered the same.
Maj_GsL_Inc. #6
Posted 09 September 2016 - 04:56 AM
Changed "grey" to "gray" but dose not seem to have fixed the issue :/
Edited on 09 September 2016 - 03:02 AM
Dog #7
Posted 09 September 2016 - 05:55 AM
On your 4th to last line, you have

term.setTextColor( inverse[barcolor] )

But barcolor hasn't yet been set (it hasn't even been declared yet) so it will be nil. You'll either need to call your Pr function first, or define barcolor outside a function and before that line.
Edited on 09 September 2016 - 03:56 AM
Bomb Bloke #8
Posted 09 September 2016 - 06:10 AM
You're also setting an invalid colour down the bottom of the script:

term.setTextColor( inverse[barcolor] )  -- At the time this line executes, barcolor is nil
Pr("blue", "lime", .2, "grey")
Cp("Done!")
sleep(2)