Displaying Text

New releases and general discussions.

Post » Mon Jun 23, 2008 2:06 pm

What could be the best way to display text for HUD display? currently i try to store my info in a variable (here "AMMO") and retrieve it as a text to tell the player a much bullet i have left.
Right now i use the TEXT object but i see only a way to display "static" info if i can say so.
i tried the ADD To Value but i didnt get anything either...
help please.. i'm lost now :(
B
2
S
1
G
4
Posts: 114
Reputation: 1,528

Post » Mon Jun 23, 2008 2:53 pm

Just do Always - Set Text (in the Text object). You can enter any number, variable, anything - the text object will show it.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Mon Jun 23, 2008 5:55 pm

Another tip, put all your HUD stuff on a new layer set above everything else. Then set that layers' scrolling to 0% so it follows the player without repositioning.
B
2
S
2
G
5
Posts: 391
Reputation: 2,432

Post » Tue Jun 24, 2008 1:23 am

thanks for the tip Jeswen.

Ashley:On thing i dont get. When i use Set text. it seem to need to be between quote?
If i want to display the value of a variable not the name of it, how do i set it?
because if its quoted it only display the name, unless i miss something.
B
2
S
1
G
4
Posts: 114
Reputation: 1,528

Post » Tue Jun 24, 2008 2:03 am

http://www.mediafire.com/?0wblyjmvsmg

I use 2 text files, because I like to keep the numbers by themselves.
B
2
S
2
G
5
Posts: 391
Reputation: 2,432

Post » Tue Jun 24, 2008 7:08 am

[quote="Border":6jmdhi0a] When i use Set text. it seem to need to be between quote?
If i want to display the value of a variable not the name of it, how do i set it?
[/quote:6jmdhi0a]
The (double) quotes mean "Use the exact text I wrote". If you leave out the quotes, you can use any expression you like. With the expression that reads a private variable, that would be:

Text: Set text to Object.Value('Name_of_the_variable')

You can use the + operator to combine bits of text with the results of expressions; the only catch is that any expressions that evaluate to numbers have to be converted into the corresponding text strings first. Fortunately, str(Expression) does just that.

Example:

Text: Set text to "X is " + str(Sprite.X) + " and Y is " + str(SpriteY) + ", and the variable is " + str(Sprite.Value('Variable'))
B
2
S
1
G
4
Posts: 60
Reputation: 1,320

Post » Tue Jun 24, 2008 3:04 pm

Delete the quotes and enter a number or variable and it works as you'd expect.

[quote="Znirk's expression":2j5sy4em]"X is " + str(Sprite.X) + " and Y is " + str(SpriteY) + ", and the variable is " + str(Sprite.Value('Variable'))[/quote:2j5sy4em]

You can use the & operator to concatenate any variables as text. For example, you could create the same string with:

"X is " & Sprite.X & " and Y is " &Sprite.Y & ", and the variable is " & Sprite.Value('Variable')

Looks a little cleaner and is easier to edit that way.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Wed Jun 25, 2008 1:45 am

thanks all.it answer all my question.'til the next one :P
ashley: i get the & stand for the str(sprite.x) to convert float and integer to string?
B
2
S
1
G
4
Posts: 114
Reputation: 1,528

Post » Wed Jun 25, 2008 3:43 pm

Yes, A & B pretty much means the same as str(A) + str(B).
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 4 guests