How do I Put An Expression Inside of a String of Text?

Just started using Construct 2? Post your questions here

Post » Sat Sep 16, 2017 7:08 pm

I'm working with a sprite font, and an instance variable called "Name" for a sprite called "Item".
I want the text to read: You got [Item.Name]. This way if the name of the Item is set to "a ball", the text will read "You got a ball."
I'm been fiddling with this for 20 minutes. If I write: You got Item.Name , Construct will come back with a syntax error. I put Item.Name in parentheses, quotes, nothing is working. What should I do?
B
7
S
1
Posts: 70
Reputation: 567

Post » Sat Sep 16, 2017 7:38 pm

Does this help?
"this is: "&aThing.name
B
26
S
6
Posts: 55
Reputation: 1,468

Post » Sat Sep 16, 2017 7:51 pm

@huZba

My mind is blown. I won't even ask how you did that, because i wouldn't be able to understand it.
Okay, I'll ask. How did you do that?! was it the & symbol? What does the & symbol do?
B
7
S
1
Posts: 70
Reputation: 567

Post » Sat Sep 16, 2017 8:01 pm

Short version:
"this is a string"
& lets you combine different types of things, like string, number and expressions like:
aThing.name

sample: "You got" & player.PickedCount & "X" & aThing.name
which can result in: You got 5 X watermelon

long version:
https://www.scirra.com/manual/78/expressions
B
26
S
6
Posts: 55
Reputation: 1,468

Post » Sat Sep 16, 2017 8:02 pm

@huZba
Thank you my friend!!
B
7
S
1
Posts: 70
Reputation: 567


Return to Beginner's Questions

Who is online

Users browsing this forum: Obi554 and 0 guests