mixing fixed and dynamic text?

Non-platform specific questions.

mixing fixed and dynamic text?

Postby Toasterman » Sun Feb 13, 2011 6:13 pm

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?
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score

Re: mixing fixed and dynamic text?

Postby schnellboot » Sun Feb 13, 2011 6:35 pm

sprintf(text,"x %i, %i, %i", x1, x2, x3);
x is your static text
x1,x2,x3 is your dynamic text
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: mixing fixed and dynamic text?

Postby Game A Gogo » Sun Feb 13, 2011 6:55 pm

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"
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: mixing fixed and dynamic text?

Postby Toasterman » Sun Feb 13, 2011 10:09 pm

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!
"If there are no stupid questions, what kind of questions do stupid people ask? Do they get smart just in time to ask a question? -Scott Adams

Hey! I've got okayish internet now! Now I can try all those cool demos I've seen!
User avatar
Toasterman
 
Posts: 75
Joined: Thu Jul 22, 2010 4:22 am
Location: Drowning in Dial-Up Ocean
Score: 7 Give a positive score

Re: mixing fixed and dynamic text?

Postby schnellboot » Sun Feb 13, 2011 10:17 pm

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);
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest