Using a dictionary over an array

Get help using Construct 2

Post » Tue Apr 02, 2013 2:23 pm

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.
B
5
S
1
G
1
Posts: 28
Reputation: 615

Post » Tue Apr 02, 2013 3:21 pm

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).
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Tue Apr 02, 2013 4:12 pm

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?

B
5
S
1
G
1
Posts: 28
Reputation: 615

Post » Sat Nov 16, 2013 1:53 pm

@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?
B
15
S
4
Posts: 138
Reputation: 2,003

Post » Sat Nov 16, 2013 5:59 pm

@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.
B
40
S
12
G
7
Posts: 603
Reputation: 7,656

Post » Sun Nov 17, 2013 7:47 am

I put a simple array into dictionary.
"player1" = "1,0,1,0,Frank,1,2340"
And I use tokenat to get the relevant data.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
61
S
16
G
9
Posts: 1,429
Reputation: 12,474


Return to How do I....?

Who is online

Users browsing this forum: Artpunk and 17 guests