Using a dictionary over an array

0 favourites
  • 6 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I've been thinking about using a dictionary to deal with storing values in my game. I would then save this as a JSON in Webstorage and Load it as a JSON at the start of the game to allow saving in the game. However, I can only find information about people using arrays for this purpose. Not to say I can't figure out how to apply this to dictionaries (seems pretty straight forward) but I'm worried that there is a reason no one is using dictionaries.

    Is it a smarter practice to use an array for storing values (level progress) that will be saved and loaded from WebStorage?

    Thank you.

  • I would say Dictionaries are actually a smarter choice, since you can name entries. For example instead of:

    Set index 0 to "John"

    Set index 1 to "Biggles"

    Set index 2 to "Smith"

    You can have:

    Set key "first_name" to "John"

    Set key "middle_name" to "Biggles"

    Set key "last_name" to "Smith"

    ...which is a lot clearer.

    Arrays are better if you need 2D or 3D data storage, though (e.g. a grid of values).

  • That was my thinking as well, Ashley.

    Does Construct 2 support nested data structures?

    Can I have a dictionary where the values are an array or even more useful another dictionary?

  • spartyon and Ashley i think the last question by spartyon on this post i a good one.

    "Can I have a dictionary where the values are an array or even more useful another dictionary?"

    any answers yet?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Dasat spartyon you can't put an atual object inside of a dictionary/array, but you can put their UID in there and pick them using that when needed.

  • I put a simple array into dictionary.

    "player1" = "1,0,1,0,Frank,1,2340"

    And I use tokenat to get the relevant data.

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