Include integer in static text (noobie, I know)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
jhend60
Posts: 44
Joined: Mon Oct 27, 2008 10:11 am
Location: behind you
Contact:

Include integer in static text (noobie, I know)

Post 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.
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post 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)
Image
Image
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

or:

Code: Select all

stringw strText = "Kills : ";
strText += int1;
strText += "/";
strText += int2;
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
fabietto
Posts: 93
Joined: Wed Sep 24, 2008 4:38 pm
Location: Plymouth, UK
Contact:

Post 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? :?
Eigen
Competition winner
Posts: 375
Joined: Fri Jan 27, 2006 2:01 pm
Location: Estonia
Contact:

Post by Eigen »

You're missing a L (meaning a wide character) in front of your " "

swprintf(temp, 256, L"Kills = %i / %i", kills, requiredkills);
B@z
Posts: 876
Joined: Thu Jan 31, 2008 5:05 pm
Location: Hungary

Post by B@z »

ahh sorry, i forgot it :?
Image
Image
fabietto
Posts: 93
Joined: Wed Sep 24, 2008 4:38 pm
Location: Plymouth, UK
Contact:

Post 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... :)
Post Reply