Author Topic: Changing text color mid sentence.  (Read 170 times)

Changing text color mid sentence.
« on: 06 Nov 2018, 10:36 »
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

  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Changing text color mid sentence.
« Reply #1 on: 06 Nov 2018, 10:56 »
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

  • been programming computers since 1981
    • I can help with AGS tutoring
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
Re: Changing text color mid sentence.
« Reply #2 on: 06 Nov 2018, 15:04 »
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

Re: Changing text color mid sentence.
« Reply #3 on: 06 Nov 2018, 15:27 »
Great.

Thanks for the reply, food for thought.

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
Re: Changing text color mid sentence.
« Reply #4 on: 06 Nov 2018, 17:58 »
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

  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Changing text color mid sentence.
« Reply #5 on: 06 Nov 2018, 18:05 »
If that solution is enough, you can position the 2nd labels behind the 1st using GetTextWidth().