How do I verify a sequence of variables

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • 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?

  • T.A.D.capx

    Tokenat-Array-Dictionary

  • korbaach

    Extremely didactic! Thank you for your kindness and for your precious time.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)