#Change bg color one by one

1 messages · Page 1 of 1 (latest)

keen bough
#

I am doing a simple snake game, but adding some stuff to make it a bit nicer. Then, I created a button, and when you press it, it should change the background color one by one, according to the list of colors I have.
But as I'm still a beginner, I can't find a way to do this. Well, it kinda works, because when you click the button, it goes to the last color in the function, which is already expected lol
And my only hope was to assign each color to a different variable, but as they all return void, and I can't do that inside a function apparently.
Another way would be to make different buttons for the different colors, but I really wanna know how to do it the first way lol
If someone could help me, I'd be really thankful

fallow gale
#

Have a colour variable, then check for colours:
if colour == 0:
Set colour one
if colour == 1:
etc.
In the end of the function add 1 to colour and then use colour = clamp(colour, 0, “MAX NUMBER OF COLOURS”)

#

Do you know what clamp does by the way?

#

Actually add 1 to the colour before the if statements

keen bough
keen bough
fallow gale
#

Colour += 1
colour = clamp(colour, 0, 2)
if statements here

keen bough
fallow gale
#

So that you can actually cycle thru colours

keen bough
#

ohh, alright, thank you so much!

fallow gale
#

Try it and come back if you have problems

keen bough
#

it worked 🙂

#

i have one more question, if you dont mind

#

if you wanna make it in a loop, you have to use for loops?

fallow gale
#

I think…

#

Don’t really use loops that often

keen bough
#

okay, thanks for your help again

sick quest
#

What is suggested works.

I have a game with a lot of colors for character customization, the method I used when I got to larger numbers was to store all of the colors in an array, and to cycle through the colors in the array, and if that was nothing after it in the array start back at key 0. I'm not saying this is correct either, but incredibly easy to expand when you get to needing to cycle through lots of objects, colors, or whatever in a larger project.