[SOLVED]Picking colours and see what current colour you have

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: Help: Picking colours and see what current colour you ha

Post by nice »

DaedalusYoung wrote:Because you need to have a variable to remember the currently selected colour. In Zilarrezko's code, you can see this, it is called currentColor. If you use numbers here, you can directly use that number to set the selected colour in love.draw.

If you use unique names for each colour, you can't do this, you'd have to make some strange and long if-block, like this:

Code: Select all

if currentColor == 1 then
    love.graphics.setColor(Red)
elseif currentColor == 2 then
    love.graphics.setColor(Orange)
elseif currentColor == 3 then
    love.graphics.setColor(Yellow)
    -- and so on
end
You can see how that is ugly and bulky. In addition, if you ever decide you want to change the colours; shuffle them up, or make a whole new palette, then you're either stuck with these old names, or you have to go through your entire program and change the variable names everywhere.
Okay I can understand that, thanks for the clarification!
:awesome: Have a good day! :ultraglee:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 9 guests