Page 1 of 1

mixing fixed and dynamic text?

PostPosted: Sun Feb 13, 2011 6:13 pm
by Toasterman
I have an actor that will display the number of lives- x1, x3, x12 etc

The "x" part will be static, it will always be x, but the 1, 2, 3, ... will change depending on your lives
textNumber = livesvar; etc

In the same actor, is there a way to have both a static text and a dynamic part of the text (like the textNumber) that could change based on a variable?

I tried some of the functions in the script reference, (sprintf looked promising) but couldn't get this to work? Is it even possible?

Re: mixing fixed and dynamic text?

PostPosted: Sun Feb 13, 2011 6:35 pm
by schnellboot
sprintf(text,"x %i, %i, %i", x1, x2, x3);
x is your static text
x1,x2,x3 is your dynamic text

Re: mixing fixed and dynamic text?

PostPosted: Sun Feb 13, 2011 6:55 pm
by Game A Gogo
I'm sure he only means to display one x!
sprintf(textm"x%02d",lives);

note, having 02 makes it display two digit at a time, remove it if you don't want that "%d"

Re: mixing fixed and dynamic text?

PostPosted: Sun Feb 13, 2011 10:09 pm
by Toasterman
Works great, thanks! :D
This will eliminate the need to have two actors, one for the fixed text and one for the dynamic.
I figured there was a way, I just didn't know how to properly use the sprintf function.

Speaking of which, what does any of this code mean?
the % deally would seem to indicate how many digits there are or something... :?

I'm able to use the codes you two gave me (it works) but I don't really know how they actually work...
I would imagine this is just general C language I lack, any help appreciated though!

Re: mixing fixed and dynamic text?

PostPosted: Sun Feb 13, 2011 10:17 pm
by schnellboot
this is what bee told me about sprintf
%i is for integer, %s for string, %d for double, %f for float

an example, you want to print "My name is xxx, I'm yyy years old" so you can type: sprintf(text,"My name is %s, I'm %i years old", xxx, yyy);