How do I colour text and attribute values using expressions? (Solved)

So, I have a 21 / 21 health bar that shows in the panel.

I want it to show in Red Text when it is 10 / X or lower

I know how to do this in the text processor, but I am using attributes to determine the panel's display:

if (game.pov.LIFE_C <= 10) 
- game.pov.LIFE = [red from here] game.pov.LIFE_C + " / " + game.pov.LIFE_M [end red]
else
-game.pov.LIFE = game.pov.LIFE_C + " / " + game.pov.LIFE_M

How do I use (font color="red")(/font), but within a non 'msg' expression?


How do I use (font color="red")(/font), but within a non 'msg' expression?

Exactly the same as in a msg, unless you're using the text processor.

  • {color:red:Your text here} is a text processor directive. You can only use it in msg, or by calling ProcessText on it first. (The text processor will convert this exactly into the code below)
  • <span style="color: red">Your text here</span> is standard HTML interpreted by the browser and will work fine in status attributes
  • <font> and color="red" are both obsolete HTML that shouldn't be used, but they will work fine as long as your browser supports them.

Have you tried it?
If a status attribute is a string, it's sent to the browser as-is, without any modification. So if you put <font style="color: red"> and </font> in it, they should work fine.

So your code (in code view)would look like:

if (game.pov.LIFE_C <= 10) {
  game.pov.LIFE = "<span style=\"color: red\">" + game.pov.LIFE_C + " / " + game.pov.LIFE_M + "</span>"
}
else {
  game.pov.LIFE = game.pov.LIFE_C + " / " + game.pov.LIFE_M
}

(Note that if you're using the web editor, that code will fail when you exit code view; because code view on the web editor crashes when it sees a < in a string. So if you're using the web editor, you'll have to miss out the < and > (or use some other brackets) and then use the GUI editor to change them)

A tweaked version that avoids the bugs of the web editor's code view:

game.pov.LIFE = game.pov.LIFE_C + " / " + game.pov.LIFE_M
if (game.pov.LIFE_C <= 10) {
  game.pov.LIFE = ProcessText ("{color:red:" + game.pov.LIFE + "}")
}

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums