Is it possible to to add subkeys to dictionary?

Get help using Construct 2

Post » Mon Aug 22, 2016 5:36 pm

Hello

In the dictionary object can I add subkeys values for a key? for example, a key named 'player' have 3 subkeys each with a different value and another key Enemy have also 3 subkeys for it:
Player
___hp:10
___attack: 5
___defense: 4
Enemy
___hp:5
___attack: 4
___defense: 3

In a json format that would be something like that I guess:
"player":[
{hp:10,
attack:5,
defense:4
}],
"enemy":[
{hp:5,
attack:4,
defense:3
}],

but if that's the correct format for C2 how should I get the hp value for player?
if not there is any way to accomplish that? I have a json file with many keys and subkeys to store into..
B
32
S
6
G
5
Posts: 437
Reputation: 6,119

Post » Mon Aug 22, 2016 6:04 pm

Yes and no. No for really subkeys. Better use an array ?

Yes for a nice workarround. Use tokenat.

Store something like this in the value = "/"&str(hp)&"/"&str(attack)&"/"&str(defense)&"/"&
(assuming hp, attack & defense are variables)

Retreive this way
hp = int(tokenat(Dictionary.CurrentValue,0,"/"))
attack = int(tokenat(Dictionary.CurrentValue,1,"/"))
defense = int(tokenat(Dictionary.CurrentValue,2,"/"))

(or Dictionary.Get("key") in stead of Dictionary.CurrentValue)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Aug 22, 2016 7:39 pm

well that's kinda a deception, the ini file did that in the past...

unfortunaly array not going to help me in my case, I will try a workaround like you said and see if it works, thanks!
B
32
S
6
G
5
Posts: 437
Reputation: 6,119

Post » Mon Aug 22, 2016 7:53 pm

Why would an array not help ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Aug 22, 2016 8:01 pm

@99Instances2Go

well I got a json file from tiled and the idea is to store some of this info, for the layout of the map I'm using array which works fine
B
32
S
6
G
5
Posts: 437
Reputation: 6,119


Return to How do I....?

Who is online

Users browsing this forum: batto and 27 guests