How do I verify a sequence of variables

Get help using Construct 2

Post » Sat Nov 14, 2015 9:47 am

Maybe it is a silly question. I've 30 variables (var1, var2, var3,...) and each one has a value with a combination of letters. I need to access this values according to the specific level in the game. To avoid using "if" for each level, I tried to use something like: set text to "var"&level. But it did not work. So, I created a variable "var" and I used it as before: set text to var&level - but it failed again. Although I know the answer, I would like to confirm this: is it wrong to access a variable in this way? If yes, anyone has another idea of how could I simplify this action with a few lines? Thanks in advance.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Sat Nov 14, 2015 10:11 am

Yup, you can't access variables like that. I recommend using an array or, even better, a dictionary. The dictionary stores its values key1: value1, key2: value2, ...

So you could have:

Level1: value1
Level2:value2

... and so on

Here's the link to the manual, if you are unfamiliar with dictionaries:

https://www.scirra.com/manual/140/dictionary
Banned User
B
6
S
3
Posts: 105
Reputation: 1,170

Post » Sat Nov 14, 2015 12:05 pm

Hi @tarik00555

Thanks for the suggestion. Although I know what is dictionary I never used it. As I understood, I need to create 30 keys and values (both strings) on start of the layout and, in this case, I can use my first solution: (set text to "dict"&str(level)) to access its data. Is it right?

***Edit

Actually, I think that I need to use something like this:

Dictionary > has key: "mykey"&str(level) > set text to: Dictionary.CurrentValue

Is it right?
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Sat Nov 14, 2015 12:57 pm

T.A.D.capx
Tokenat-Array-Dictionary
Image
B
65
S
23
G
7
Posts: 1,502
Reputation: 10,890

Post » Sat Nov 14, 2015 1:24 pm

@korbaach

Extremely didactic! Thank you for your kindness and for your precious time.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041


Return to How do I....?

Who is online

Users browsing this forum: darkrealos, Rhindon and 15 guests