0 Favourites

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

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

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

  • Construct 3

    Buy Construct 3

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

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

    EDIT:

    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)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,132
karshinkoff's avatar
karshinkoff
Unread hot topic
68 8,937
Wrangler's avatar
Wrangler
Unread hot topic
56 12,261
zyblade's avatar
zyblade