Is it possible to to add subkeys to dictionary?

0 favourites
  • 5 posts
From the Asset Store
Kids Game
$24.50 USD
50% off
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • 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..

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

  • Try Construct 3

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

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

  • Why would an array not help ?

  • 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

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