Default values for love.graphics.setColor

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Default values for love.graphics.setColor

Post 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.
When I write def I mean function.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Default values for love.graphics.setColor

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Default values for love.graphics.setColor

Post 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).
User avatar
slime
Solid Snayke
Posts: 3170
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Default values for love.graphics.setColor

Post 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. :P
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Default values for love.graphics.setColor

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests