# Changing the colour of object real time?

I have an object that has to change the redness of itself from green to red on the basis of a variable like health! You might have seen in games where our health becomes more reddish from greenish when out health decreases! How do I do that?? I tried once but it didnt change the colour!! I did like this:

I know that there is force instead of health and instead of being red when less i have to make it red when it is high!!
Please How do I do this??

The color values are red;green;blue.
If you want to go from green to red, start with green = 255, red = 0 and adjust values until green = 0 and red =255.
You donâ€™t need to change blue.

Create a text object on the scene to display your color calculations. That way, you can check if your code works as expected (0->255;255->0;0->0).
You need to figure out the calculation depending on your variable.

1 Like

And can you explain this?? I already knew the things you just said!!

There is no change in colour!!
Your reply was not helpful! Maybe help after looking this! Oh It is not properly closed !! So but this works neither why???

Your syntax is a mess. There is a blue button next to the color picker, you need to use it.

pay attention to syntaxe

`VariableString(Red) + ";" + VariableString(Green) + ";0"`

1 Like

That is an interesting way saying â€śI donâ€™t know what is wrong and I donâ€™t understand you, could you please explain it why is this not working?â€ť

Dude, if you donâ€™t know something do not pretend you do because we know you donâ€™t, otherwise you would not ask bull
Leave the horses and your high minded attitude at home and start at the ground.

2 Likes

You should learn more about syntax and the difference between a numerical value, and a text value.
It is because of your lack of knowledge in this area that what you do does not work.

1 Like

Is this not correct?
But it shows black

Do you mean like my spaces between â€¦ and ; is wrong or I have to add that + sign??
I didnt understand you ! can you explain a little more!

Plz Help First and then comment on my attitude!!

Help wanted

Yeah sure.
Variable(green) return a number value but you are trying to use it as a string, you wan to convert the value to string first using the ToString() expression that you can find in the expression editor that Gruk mentioned and then apply in the value field of the color as Bouh told you.
Everything is explained on the wiki and you can find all the expressions in the expression editor but as I can see from the screenshot, you canâ€™t even use the search on the wiki
Are you asking how to search or what?

Yet you behave like some sort of general expecting results on command. Thatâ€™s not the way to ask for help. If you need further help, try to change your attitude maybe.

2 Likes

You still donâ€™t pay attention to what youâ€™re being told.
The articles on the wiki have been given to understand the type of value you need.

The color value field is a text field. (Button blue on screen from Gruk)
The other types on buttons :
http://wiki.compilgames.net/doku.php/gdevelop5/all-features/functions

Yes, you need double quotes BUT.
If `Red = 0` (Numerical)
When you call a variable this way `VariablesString(Red)` will return â€ś0â€ť (String)
Because `VariablesString()` Returns the value as String.
`Variable()` Returns the value as Numerical.

`;` is a color separator, it must be type String.
`+` is for concatenated values, add this betweens String or Numerical values

I lock this topic during 1 day, you need try to understand thes responses, read the wiki page and test the differents type of values.

When you need help please be more friendly in next responsesâ€¦

1 Like

This topic was automatically opened after 18 hours.