Store color as a variable

To change the global color of a sprite, i tried using,


And modified the scene variable Pink to the rgb values,


But it’s still not changing the color of the White sprite i used. What is probably wrong or is it even possible to do ?

I guess because you are using an Integer variable to store the RGB values which is not possible or you just using the wrong expression.
Make sure you are using a String variable to store the color “180;0;140” and then use the expression like so:


Alternatively, store the RGB values in separated integer variables if it something you want like:

R = 180 G = 0 B = 140
And then use the expression like so:

ToString(Variable(R)) + ";" + ToString(Variable(G)) + ";" + ToString(Variable(B)) 
1 Like

The colors seem very different compared to the rgb values i put in. Like being a lot darker. Pink shows up as dark green. I tried changing to different colors using the variable but all of them are producing different darker colors compared to the rgb values i put in. I am using a white sprite which is stretched from a small size to create a square of any color with rgb values.

Changing the string with “” and adding VariableString to expression was successful. :unamused:

I can’t really comment on this one, I don’t have a good eye for colors and I’m not an artist with any clue what could be the problem, but I have just created a quick test: … lor-picker
This project generate a bunch of random colors, I was compare some of them to the ones I get in Gimp, and they look exactly the same to me, including the Pink color you mentioned.

I think i have reproduced the problem in this attachment by adding the scene variable in the same project you send me. I think you can take a look at it. The color is very different from rgb values in scene variable. You can test the same rgb value in gimp and see that it produce darker pink instead of the wrong dark blue in gdevelop. You can add different rgb value as string to the scene variable as well and see that they are different from how they should be.
Color In Scene (3.87 KB)

It seems like the problem is, in the variable editor you have entered the value as “180;0;140”.
When you enter a string value in the variable editor, you don’t need to use the “” signs, just simply enter
180;0;140 without using the “”

I don’t know why, but it is just the way it is, in the variable editor don’t need to use “”
If I remove it, it seems to solve the problem I get the proper pink color.

Yes. It seemed to have corrected in mine as well. Although it would be interesting to know how it maintained a different color eventhough the string wasn’t right and what rgb values it chose it from that anomaly and how it happened. When i followed it earlier, it seemed like i followed both parts of the methods you told eventhough one was just necessary. Thanks a lot.