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

[1.6] Window API: set*Color does not work correctly

Started by eonasdan, 29 March 2014 - 06:38 PM
eonasdan #1
Posted 29 March 2014 - 07:38 PM
ComputerCraft Version Information: 1.6

Description of Bug: Window API: set*Color does not work correctly

Steps to Reproduce Bug:
  1. Connect a standard computer to an advanced monitor
  2. Create a Window inside the monitor
  3. Attempt to set the background color
  4. Receive error at
    win.setBackgroundColor(colors.black)
  5. Comment out background color
  6. Receive error at
    win.setTextColor(colors.white)



local monitor = peripheral.wrap("top")
local win = window.create(monitor, 1,1,20,10,true)

if (win.isColor()) then -- returns true
	win.setTextColor(colors.white) -- gives "Colour not supported" AFTER line below is commented out
	win.setBackgroundColor(colors.black) -- gives "Colour not supported"
end

GopherAtl #2
Posted 29 March 2014 - 07:41 PM
confirmed, easy fix too, in the window API the returned window object's set(Text|Background)Color functions test term.isColor instead of parent.isColor.
Shazz #3
Posted 30 March 2014 - 12:22 AM
confirmed, easy fix too, in the window API the returned window object's set(Text|Background)Color functions test term.isColor instead of parent.isColor.

Confirmed, was about to report this bug.

By the way this is only true for window.isColour(), window.isColor() should work correctly.
From the window API itself:

	function window.isColor()
		return parent.isColor()
	end
	function window.isColour()
		return term.isColor()
	end

Simplest solution:

	function window.isColor()
		return parent.isColor()
	end
	window.isColour = window.isColor

EDIT:
Apparently the setTextColour/setTextColor & setBackgroundColour/setBackgroundColor functions do the checking themselves (I thought they would've used the previously defined window.isColour/window.isColor).
Anyway, it also uses term.isColor to check:

    local function setTextColor( color )
	    if not term.isColor() then
		    if color ~= colors.white and color ~= colors.black then
			    error( "Colour not supported", 3 )
		    end
	    end
	    nTextColor = color
	    if bVisible then
		    updateCursorColor()
	    end
    end
    local function setBackgroundColor( color )
	    if not term.isColor() then
		    if color ~= colors.white and color ~= colors.black then
			    error( "Colour not supported", 3 )
		    end
	    end
	    nBackgroundColor = color
    end
Edited on 29 March 2014 - 11:27 PM
dan200 #4
Posted 02 April 2014 - 02:01 PM
This was fixed in ComputerCraft 1.61, closing