Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » My problems with a dialouge function

This thread is locked; no one can reply to it. rss feed Print
My problems with a dialouge function
Neil Black
Member #7,867
October 2006
avatar

I want to make a dialouge function that prints the message one character at a time. I know how to make a function that displays an array of chars one a t a time, that's just a simple for loop, but I can't figure out how to assign a string to that array. Is it even possible to assign a literal string to an array of chars? If not, is there a way I can display a literal string one character at a time, with a slight delay between each character? I really need some help on this one.

Anyone?

Jeff Bernard
Member #6,698
December 2005
avatar

It's the same thing, to display a string one character at a time as displaying one character at a time from char*.

std::string message = "Hello world!";
int x = 0, y = 0;
for (int i = 0; i < message.size(); i++)
{
   textprintf_ex(buffer,font,x,y,makecol(255,255,255),-1,"%c",message<i>);
   x += WIDTH_OF_FONT_CHARACTER; // whatever your font may be

   // whatever else you need to do, ie- blit buffer to screen

   rest(SOME_AMOUNT_OF_TIME);
}

As for assigning a string to a char*, you'll want a function like:
usprintf

--
I thought I was wrong once, but I was mistaken.

Neil Black
Member #7,867
October 2006
avatar

Okay, how do I use usprintf to display a string one character at a time, with a delay between them, or to assign a literat string to a char array?

Audric
Member #907
January 2001

PossumDude0, you seem to confuse the 2 answers to the 2 questions...

In the above code, message<i>is the i-th character of the std::string message.

Unrelatedly, usprintf() is one way to convert (make of copy) a std::string into a C-style, null-terminated array of characters. See some libc documentation of sprintf() for reference about the usage.

Neil Black
Member #7,867
October 2006
avatar

Ok, I just didn't look at the code closely enough. Sorry.

Thanks, by the way, for helping me.

Go to: