Page 2 of 2
Re: Default values for love.graphics.setColor
Posted: Mon Jun 03, 2013 4:01 pm
by kikito
I don't like this because it's easy to mask a bug:
Code: Select all
local backgroundColor = {255,0,0}
...
love.graphics.setColor(backGroundColor) -- the G is uppercase here, will set the color to white instead of red, with no error message
If this is a concern, I would add this at the beginning of your game:
Code: Select all
love.graphics.resetColor = function() love.graphics.setColor(255,255,255) end
And use resetColor instead of setColor.
Re: Default values for love.graphics.setColor
Posted: Mon Jun 03, 2013 7:19 pm
by T-Bone
kikito wrote:I don't like this because it's easy to mask a bug:
Code: Select all
local backgroundColor = {255,0,0}
...
love.graphics.setColor(backGroundColor) -- the G is uppercase here, will set the color to white instead of red, with no error message
If this is a concern, I would add this at the beginning of your game:
Code: Select all
love.graphics.resetColor = function() love.graphics.setColor(255,255,255) end
And use resetColor instead of setColor.
This is indeed a valid point.
Re: Default values for love.graphics.setColor
Posted: Mon Jun 03, 2013 8:31 pm
by bartbes
There is a hacky workaround, that involves the difference between nothing and nil (it exists, but only in c), this is in fact used in 0.9.0 for setCanvas, but it's a bit weird that setColor() would not equal setColor(nil).
Re: Default values for love.graphics.setColor
Posted: Mon Jun 03, 2013 8:39 pm
by slime
bartbes wrote:There is a hacky workaround, that involves the difference between nothing and nil (it exists, but only in c), this is in fact used in 0.9.0 for setCanvas, but it's a bit weird that setColor() would not equal setColor(nil).
I don't actually like the setCanvas thing, it's inconsistent and annoying when you actually want to take advantage of passing a potentially nil value to setCanvas.
Re: Default values for love.graphics.setColor
Posted: Tue Jun 04, 2013 3:42 pm
by Inny
I vote for throwing errors on invalid data going through love's API functions. That sort of Mechanism Vs Policy design comes up here and having a consistency there is important.