|
Variables in textout_ex... |
Jim Simon
Member #4,744
June 2004
|
I have the following line of code: textprintf_ex(buffer, font, p1stuff.chp + "/" + p1stuff.mhp, 705, 501, color_text, -1); I am getting errors concerning using the variables in the string. The variables represent current hit points and max hit points. How can I make this work properly? Thanks in advance, |
ReyBrujo
Moderator
January 2001
|
Are you using C++? It seems so. If you are using C: char temp[512]; snprintf(temp, sizeof(temp), "%d/%d", p1stuff.chp, p1stuff.mhp); textprintf_ex(buffer, font, temp, 705, 501, color_text, -1); If you are using C++ and STL (not tested): // textprintf_ex needs a char pointer, not a string, so I construct a // temporary string and call c_str(), which returns "a pointer to a // null-terminated array of characters representing the string's contents" // according to the STL documentation. textprintf_ex(buffer, font, string(p1stuff.chp + "/" + p1stuff.mhp).c_str(), 705, 501, color_text, -1);
-- |
Jim Simon
Member #4,744
June 2004
|
Would this work with textout_ex as well?
|
ReyBrujo
Moderator
January 2001
|
Yes, or with any other function that needs a char pointer as argument. -- |
Jim Simon
Member #4,744
June 2004
|
Thanks Rey
|
Erkle
Member #3,493
May 2003
|
void textprintf_ex(BITMAP *bmp, const FONT *f, int x, y, color, bg, const char *fmt, ...); Try: textprintf_ex(buffer, font, 705, 501, color_text, -1, "%d/%d", p1stuff.chp, p1stuff.mhp);
If the writing above has offended you, you've read it wrong.....fool. |
X-G
Member #856
December 2000
|
Quote: char temp[512]; snprintf(temp, sizeof(temp), "%d/%d", p1stuff.chp, p1stuff.mhp); textprintf_ex(buffer, ... why in the world of jumping jehosephats would anyone do that? textprintf_ex(buffer, font, 705, 501, color_text, -1, "%d/%d", p1stuff.chp, p1stuff.mhp); -- |
ReyBrujo
Moderator
January 2001
|
Because it is 5:19 AM and at this hour I focus either on C++ or C -- |
X-G
Member #856
December 2000
|
Do we need to point out that the syntax you used for textprintf_ex isn't even valid..? -- |
Don Freeman
Member #5,110
October 2004
|
X-G said: Do we need to point out that the syntax you used for textprintf_ex isn't even valid..? Hehehehe...:D -- |
ReyBrujo
Moderator
January 2001
|
I just copy/pasted his example -- |
Don Freeman
Member #5,110
October 2004
|
I know...but I couldn't pass up a ! Hehehe... -- |
ReyBrujo
Moderator
January 2001
|
That is Matthew's fault for not adding intellisense to the reply box -- |
|