Page 1 of 1

Include integer in static text (noobie, I know)

Posted: Sat Nov 08, 2008 1:28 pm
by jhend60
Hi all
I have made a simple static text box which says how many points you have in my game. I need to make it like this:
"Kills = " int1 + "/" and int2
int 1 is the kills, int2 is the required kills
How can I add integers like that too strings? I saw it done in the demo, I am just not sure how. I am sure this is really simple, but I am really tired right now (midnight here) and had a busy day so help will be appreciated.

Posted: Sat Nov 08, 2008 1:36 pm
by B@z
wchar_t temp[256];
swprintf(temp, 256,"Kills = %i / %i", kills, requiredkills);
and add temp to your static text (when creating, or with setText)

Posted: Sat Nov 08, 2008 4:51 pm
by Acki
or:

Code: Select all

stringw strText = "Kills : ";
strText += int1;
strText += "/";
strText += int2;

Posted: Mon Nov 10, 2008 7:26 pm
by fabietto
Uhm... why the first solution doesn't work for me? :shock:

Using the B@z approach (which I've seen employed also on tutorial 14) I get the following error when I call the swsprintf() function.

/Users/fruini/Documents/University/Plymouth/MAVs/3DSimulations/MAVs3D/gui.cpp:229: error: cannot convert 'const char*' to 'const wchar_t*' for argument '3' to 'int swprintf(wchar_t*, size_t, const wchar_t*, ...)'

I was looking here since I'm trying to convert some integer values into wchar_t in order to pass them to an IGUIEditBox...

Any hints? :?

Posted: Mon Nov 10, 2008 7:41 pm
by Eigen
You're missing a L (meaning a wide character) in front of your " "

swprintf(temp, 256, L"Kills = %i / %i", kills, requiredkills);

Posted: Mon Nov 10, 2008 8:15 pm
by B@z
ahh sorry, i forgot it :?

Posted: Mon Nov 10, 2008 10:23 pm
by fabietto
Eigen wrote:You're missing a L (meaning a wide character) in front of your " "

swprintf(temp, 256, L"Kills = %i / %i", kills, requiredkills);
Yes, in this way it works perfectly...

Code: Select all

IGUIEditBox *editBox;
wchar_t temp[256];
int a = 10;

editBox = gui_env->addEditBox(L"0", rect<s32>(915,28,1015,48));
swprintf(temp, 256, L"%i", a);
editBox->setText(temp);
Many thanks... :)