Changing text color mid sentence.

Started by The creature, Tue 06/11/2018 10:36:54

Previous topic - Next topic

The creature

Hi I was wondering  - like the post title says - if you can change the color text mid sentence to highlight keywords.

For example:
if (Parser.Said("navigation"))lDetails.Text=("Command Example:[['navigate b1 to r2'[Moves bot1 to Room1");

The text is set to white, is it possible to change "navigate b1 to r2'[Moves bot1 to Room1" to say green?

Kind regards
C

Khris

Not with built-in texts like those appearing on labels or when you call Display(). You would have to program your own font rendering, basically. Split the text accordingly, measure it, draw colored text on a DrawingSurface, display it using a GUI or GUI Button. Not fun :)

dayowlron

You could create a graphic then create an object in the room then set it visible when you want it displayed, but the text would be static so couldn't use any variables to create it.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

The creature

Great.

Thanks for the reply, food for thought.

Cassiebsg

You can try and use a GUI with labels, since you can change the colour of the labels.
So you would have:

lbCommand.TextColor = 15; // white
lbMoves.TextColor = 2; // Green

Then you just pass the text to the label on the GUI...

lbCommand.Text = "navigate b1 to r2";
lbMoves= "Moves bot1 to Room1";

This is a simple way to do it. But does require that "navigate b1 to r2" isn't "move b1 to r2"... Though if that's a possibility, you can also adjust the x,y of the label in script if needed... but seems to me that the green will always be on the next line, and thus will always start right bellow the command.

Like:

navigate b1 to b2
Moves bot1 to Room1

I'm just simplifying Khris's idea, though I'm skipping the "DrawingSurface" (mostly cause I'm a chicken and haven't bothered to learn how to use that yet. (laugh) ).

Anyway, just a practical solution on how to do it.
There are those who believe that life here began out there...

Khris

If that solution is enough, you can position the 2nd labels behind the 1st using GetTextWidth().

SMF spam blocked by CleanTalk