How do I use a dictionary to get info in a array

0 favourites
  • 4 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi,

    I am not sure what the best way is to do the following:

    I am creating a level up system in my game and i am not sure what to use ( array or dictionary ) for my needs.

    I have a level up table, for example: lvl 1 = 83 exp, lvl 2 = 150 exp, lvl 3 = 300 exp.

    Now what i tried to do is creating a dictionary with a key named: expTable.

    As key i added "83,150,300".

    So the result is like:

    Dictionary > Add key: "expTable" value: "83,150,300".

    Is there any way to get for example the "300" in that array? I can not find the right solution.

    I need something like: Dictionary > Get key "expTable(3)". As where the 3 would be the third number in the "83,150,300" value.

    Any help is really appreciated. 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
  • [quote:ceruq7tq]tokenat(src, index, separator)

    Return the Nth token from src, splitting the string by separator. For example, tokenat("apples|oranges|bananas", 1, "|") returns oranges.

  • I think one wants to use Token something like

    Tokenat(Dictionarykey(expTable), "," ,3)

    FIrst entry of Token gets the data which is "83,150,300"

    Second entry tells what the seperator is, in this case a comma ","

    The third entry is the nth value one wants. I picked 3 to get 300

    Hope it helps

    Edit: wow ninja haha

  • Thanks both for your answers!

    This time i was so close! I did read some things about tokenat.

    What i tried was: "Exp"& tokenat(Dictionary.Get("expTable"),0,",")

    Got the right explanation now ! Thanks!


    Oh wow, i actually had it all this time before ( as shown above ) the thing is i just hadn't set the key itself yet

    Though this explanation is pretty clear to understand since i had no idea why it was working !

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