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
#Change bg color one by one
1 messages · Page 1 of 1 (latest)
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
ohh, okay, that makes much more sense. I was thinking about a really difficult way of doing it, and you just solved it with an if statement lol, thank you
actually no
Colour += 1
colour = clamp(colour, 0, 2)
if statements here
is it like, a mimimum and maximum limit for something? because you first defined it as color, then the min, which is 0, and the max
Yes sir
So that you can actually cycle thru colours
ohh, alright, thank you so much!
Try it and come back if you have problems
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?
If you would want it or anything in a loop you can use the for I in something loop
I think…
Don’t really use loops that often
okay, thanks for your help again
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.