How to change the colour of certain letters in text?

Mar 1, 2010 at 11:23pm
It's been brought up before how to change ALL of the text, but how would I change just specific letters?

For example how would I display ABC, but have A red, B blue, C green?

Thank you
Mar 2, 2010 at 12:23am
I would write a function with a switch statement that counts for every letter, and if it is that letter , set the color as you would for the whole text, and then move onto the next letter.

the function should take in the text one letter at a time
Last edited on Mar 2, 2010 at 12:23am
Mar 2, 2010 at 1:04am
The possibility really depends on the API you are using to accomplish that color change. I'm not sure (but I'm no expert) if the windows console API has the tools to change the color of any text coming up, but not just all the text.
Mar 2, 2010 at 2:24am
On Windows, use SetConsoleTextAttribute()
http://www.google.com/search?btnI=1&q=msdn+SetConsoleTextAttribute

If you are on *nix, let me know.
Mar 2, 2010 at 9:21am
Ah forgive me. I didn't mean to ask for each letter to be a specific, rather I want to be able to change the next character to another colour?

Let's say I had the word COOL. How would I make C blue, first O white, second O light blue, L white.
Mar 2, 2010 at 1:07pm
What?
Mar 2, 2010 at 1:14pm
I would make the word COOL light up and flicker with lines like the sun coming out of it, how do you do that? Or make the colors light up in series then when it gets to the L have it detach, swing, then drop off the screen.
Last edited on Mar 2, 2010 at 1:18pm
Mar 3, 2010 at 11:17pm
Oh my..haha

I used to play MUDs way back when. I think it stands for Multi User Dungeon.

http://apexwebgaming.com/images/screens/10_1.jpg

As you can see, different words and such are in different colours. I'm not sure what language they use but I want to be able to do this in a single player game text game I'm making with C++

For example in HTML
<font color="#0000FF">C</font><font color="#FFFFFF">O</font>

etc..
Mar 3, 2010 at 11:30pm
ASCII game ftw. Just play dwarf fortress or Angband and you'll see what people can pull off with a setspace font alone. (ASCII Sector and Legerdemain are other great ones but I'd say those two are the classics)
I'm not sure you could make the words flicker. But using windows API, you could use the function that Duoas directed you to, SetConsoleTextAttribute(), to change the color of the first letter, C, followed by another change, then the next letter, O, etc. As for moving the text around you'll probably be better off moving to a console library like curses that is designed for that kind of functionality. curses, being a terminal/console library, is specifically designed to pull off character and cursor manipulation in setspace console fonts. (Angband is a great example of curses. The entire interface is done in n/pdcurses.) Your life will just get really complicated with all that cursor shuffling using any normal API (http://www.cplusplus.com/forum/beginner/1258/ for how to do that in windows, among others).
Mar 3, 2010 at 11:57pm
Ah yes I've played Dwarf Fortress and I've heard of Angband =) I'm more of a NetHack person myself. I will look into SetConsoleTextAttribute(). My game will definitely be a lot simpler than these games we mentioned. No walking around and such, just simple options like 1) Attack 2) Defend, but it would be nice if different monsters had different names or weapons had different colours in them
Mar 4, 2010 at 12:16am
Again, curses is by far the most powerful option.
Topic archived. No new replies allowed.