To print a string in a specific color use SetConsoleTextAttribute (google it). If you want to change a color of some string without redrawing everything, I think you should take a look at ncurses lib.
@disch
I tried it and ran into nothing but trouble man i couldnt even get crap to compile! why mess with that when what i have is working fine, when this project is done maybe ill check it out but until then im stickin to my guns 3/4 of my main engine is in place soon its gonna be mostly all content and some fancy puzzles!
@hamsterman
Will that work with a tri-bool situtaton though and 3 colors
i have setup a switch system so that the player can activate a quest, cancel it or complete it. and it toggles the status based on 2 bools outa 3.
I tried it and ran into nothing but trouble man i couldnt even get crap to compile!
I agree that getting it set up is a bit troublesome. But you only have to do it once, and it's well worth it.
why mess with that when what i have is working fine
Because what you're doing now is sinful and wretched. And in fact, the roundabout way you have to do things is ultimately making the overall process much more difficult for yourself than it would be to just take an hour or two to work out the kinks with getting SFML set up.
when this project is done maybe ill check it out
I suppose I can understand not wanting to abandon a project. But I would certainly hope that you would not do what you're doing again in any new project you start.
@Disch yeah i plan to try to get SFML working in the future. But since my program is pretty close to fully working other then adding more content im going to wait until its done, i wouldn't mind your assistance with setting up SFML though, i followed the tutorials to set it up and believe me i did it exactly as it said to, ive set up databases and ran private game servers so setting up a few settings for the compiler is childs play for me.
@hamsterman
not sure if you got my previous message, but won't what you described just reupdate the coloring when it changes, i want 3 seperate colors to be used on a single string which is altered based on which bool is currently set to true.
Right now i have a QuestLog display function, a QuestManager function and a QuestUpdater function the player loads the quest log to view the quests active, uses the manager to maintain, view the quest text and change stuff. The updater updates the status based on the actions in the manager. The only thing i need to figure out is how to change the string's color based on the bool. Its a 3 way switch using 2 strings and 3 bools. If anyone has any ideas id appreciate it. thanks
I accually have a really good idea, is there a way to specifically set a string to a certain color? i could use it in if else statement and add that to my updater function to update both the status and the color.
class Text
{
private:
std::string str;
int color;
public:
enum
{
Black = /*whatever code is black*/,
White = /*whatever code is white*/,
/*etc*/
};
Text(const std::string& s = "", int c = White) // or instead of White, use whatever you want
// the default color to be
: str(s)
, color(c)
{ }
void SetColor(int clr)
{
color = clr;
}
void Print() const
{
/* insert whatever crazy code you have to change text color here*/
std::cout << str;
}
};
Then you can do stuff like this:
1 2 3 4 5 6 7 8 9 10 11 12
Text menu("Here are your menu options:\n""1) Do something\n""2) Do something else\n",
Text::Blue
);
menu.Print();
// then say you want to change the color to red:
menu.SetColor(Text::Red);
menu.Print();
I don't understand your code, ive just started working with arrays to a limited extent i still don't know structs and classes yet. Also how would that effect the strings because they have to be used to show the text state from the bool checks.
Ok im going to try to explain what im doing in simple words lol
I have 1 string. It represents the status of the quest.
I have 3 bools 1 for each of the 3 quest states.
I use the bools to check the state. Then i use if else to switch the single string = to 1 of 3 other strings ACTIVE, INACTIVE, COMPLETED..... now for each of the 3 quest states i want to be a different color.... Grey for inactive, white for active and green for completed.
can you make the colors grey for unknown, red for inactive, white for active and green for complete? not sure what kind of color code you using, i am used to 1-15 using hconsole
and of course soon as u posted that, i already was working on a work around to do it, i realized the if else statements could be used since the console works on a line to line basis to hand write out all 3 states LOL
As for the states no there can only be 3 accually cause by default they will be set to inactive.
there is no unknown..... but each quest will have its own check/state