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

Get help using Construct 2

Post » Fri Oct 16, 2015 1:35 pm

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!
B
10
S
4
G
3
Posts: 169
Reputation: 2,519

Post » Fri Oct 16, 2015 2:12 pm

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



Image
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Fri Oct 16, 2015 2:12 pm

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
It's time for me to return the favor :)
B
32
S
9
G
9
Posts: 132
Reputation: 5,370

Post » Fri Oct 16, 2015 2:17 pm

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 :oops:

Though this explanation is pretty clear to understand since i had no idea why it was working :)!
B
10
S
4
G
3
Posts: 169
Reputation: 2,519


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests