calling variable with a string

Get help using Construct 2

Post » Mon Mar 23, 2015 8:08 am

Is it possible to call global variables by a string?

Like if you have these global variables:
orange_1
orange_2
orange_3

and you wanted to be able to call the variables with a combination of the text strings:

"orange"
and
"1"
"2"
"3"

from my testing so far, the expression doesn't look for a variable with that name it just treats it as the base text/string. I didn't find any system expressions that allow you to use a string to find a variable. Am I missing something?
B
16
S
1
G
3
Posts: 43
Reputation: 2,597

Post » Mon Mar 23, 2015 8:14 am

Nope.
You can use those values contained in a variable however.
Like if mygvariable= "orange_"&1
Image ImageImage
B
166
S
49
G
155
Posts: 8,110
Reputation: 100,741

Post » Mon Mar 23, 2015 4:50 pm

Thanks for the quick reply! I'll just go the longer route to make it happen.
B
16
S
1
G
3
Posts: 43
Reputation: 2,597

Post » Thu Mar 26, 2015 6:21 pm

using dictionary, perhaps?
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
61
S
14
G
2
Posts: 286
Reputation: 6,521

Post » Fri Mar 27, 2015 5:46 am

As far as placing var in text strings is rather straight forward but will require a bit of labor.

var "Apple_Red" = 10

Start of Layout > Set text for Textbox to "Have you collected all the apples?"

If Yes_btn is clicked
"Apple_Red" >= 8
set Textbox to "Great now I can make that pie"

"Apple_Red" < 8 then
set Textbox to "Oops, You need to collect "& 8-"Apple_Red" & "Red Apples. Please look for them"


So it can be done but you need to edit the string to have the variable in it instead of a string. '&' is what you use to bind two things together so all you need is to have "The text string" & variable & "last text string."
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245


Return to How do I....?

Who is online

Users browsing this forum: mekonbekon, plinkie, Yahoo [Bot] and 2 guests