Page 1 of 1

Text shows variable number

PostPosted: Wed Aug 03, 2011 6:03 pm
by code4242
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.

Re: Text shows variable number

PostPosted: Wed Aug 03, 2011 6:46 pm
by lcl
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

Re: Text shows variable number

PostPosted: Wed Aug 03, 2011 7:23 pm
by code4242
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?

Re: Text shows variable number

PostPosted: Thu Aug 04, 2011 9:45 am
by lcl
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

Re: Text shows variable number

PostPosted: Thu Aug 04, 2011 4:35 pm
by code4242
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

Re: Text shows variable number

PostPosted: Thu Aug 04, 2011 5:58 pm
by lcl
: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)

Re: Text shows variable number

PostPosted: Thu Aug 04, 2011 6:15 pm
by code4242
By right-to-left I mean different alignments. Like this.
Image

Re: Text shows variable number

PostPosted: Thu Aug 04, 2011 8:00 pm
by lcl
Ahh, now I see. :)
I don't know how one could make that, though. :P

Re: Text shows variable number

PostPosted: Thu Aug 04, 2011 8:05 pm
by code4242
That's alright, I found a better way to fix this anyways. Thanks for your help though! :D