Text shows variable number

You must understand the Game Editor concepts, before post here.

Text shows variable number

Postby code4242 » Wed Aug 03, 2011 6:03 pm

I'm trying to make a number-based health bar. Basically, I want the variable number to show up as text on the screen.
Example:
If the variable "hp" equals 106, the text would read "106" on the screen.
This would also have to support decimals, so please let me know if that will be a problem or not.
Current project: Teratism
User avatar
code4242
 
Posts: 40
Joined: Tue Dec 11, 2007 9:01 pm
Location: Sitting at my laptop :D
Score: 0 Give a positive score

Re: Text shows variable number

Postby lcl » Wed Aug 03, 2011 6:46 pm

Just make "hp" a real (float point number) variable, then it can handle decimals.
And to show the hp:

Actor - draw actor - script editor:
Code: Select all
sprintf(text, "HP: %f", hp);


Now what will be seen on screen if hp equals 10 is this:
HP: 10

Or if hp equals 10.2:
HP: 10.2

Did that help? :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Text shows variable number

Postby code4242 » Wed Aug 03, 2011 7:23 pm

Thanks! That's exactly what I needed!
Is there also any way to have the text line up right-to-left?

EDIT: Hmm, for some reason, after making the variable a "real" instead or an "integer", the text no longer shows the variable. Any ideas?
Current project: Teratism
User avatar
code4242
 
Posts: 40
Joined: Tue Dec 11, 2007 9:01 pm
Location: Sitting at my laptop :D
Score: 0 Give a positive score

Re: Text shows variable number

Postby lcl » Thu Aug 04, 2011 9:45 am

code4242 wrote:Thanks! That's exactly what I needed!
Is there also any way to have the text line up right-to-left?

..what do you mean? :)
code4242 wrote:EDIT: Hmm, for some reason, after making the variable a "real" instead or an "integer", the text no longer shows the variable. Any ideas?

Are you sure you didn't change the variable name?
If you copied my code your variable has to be named hp.
And note that in the sprintf() - function there has to be that %f. :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Text shows variable number

Postby code4242 » Thu Aug 04, 2011 4:35 pm

Oh, okay. I had %d, not %f. It works now. And don't worry about the right-to-left, I don't need it after all.
Thanks for all the help! :D
Current project: Teratism
User avatar
code4242
 
Posts: 40
Joined: Tue Dec 11, 2007 9:01 pm
Location: Sitting at my laptop :D
Score: 0 Give a positive score

Re: Text shows variable number

Postby lcl » Thu Aug 04, 2011 5:58 pm

:D
No no, tell me what you mean by right-to-left, do you mean scrolling text, like this: viewtopic.php?f=4&t=9329
(Donwload the demo to see what it is)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Text shows variable number

Postby code4242 » Thu Aug 04, 2011 6:15 pm

By right-to-left I mean different alignments. Like this.
Image
Current project: Teratism
User avatar
code4242
 
Posts: 40
Joined: Tue Dec 11, 2007 9:01 pm
Location: Sitting at my laptop :D
Score: 0 Give a positive score

Re: Text shows variable number

Postby lcl » Thu Aug 04, 2011 8:00 pm

Ahh, now I see. :)
I don't know how one could make that, though. :P
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Text shows variable number

Postby code4242 » Thu Aug 04, 2011 8:05 pm

That's alright, I found a better way to fix this anyways. Thanks for your help though! :D
Current project: Teratism
User avatar
code4242
 
Posts: 40
Joined: Tue Dec 11, 2007 9:01 pm
Location: Sitting at my laptop :D
Score: 0 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron