question

austerepeasant avatar image
austerepeasant asked

Is it possible to store are retrieve PlayerData as an Array?

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

austerepeasant avatar image austerepeasant commented ·

I found that if I send a string "[0,1,2,3,4]" and then retrieve it and do JSON.parse(Data.objName.Value) it will return it as an array.... is there a better way to send it though? When I try JSON.stringify([0,1,2,3,4]) it stores all the values as objName[0]=0 objName[1]=1, etc.

0 Likes 0 ·

1 Answer

·
brendan avatar image
brendan answered

Player Data is stored as strings in the service. The best way to manage converting back and forth between the data types you want (arrays, in this case) and that string would be via ToString operations or using JSON and using stringify/parse, as you saw in your example. The problem with the array in your example is that you don't have a defined key/value structure in the data you were passing in as your JSON, so the JSON serializer "helped" by adding that. If you were to instead make an array object like:

var nums = [ 0, 1, 2, 3, 4 ];

And then stringify that, you'd get the string I believe you are expecting.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

austerepeasant avatar image austerepeasant commented ·

thanks Brendan, that didn't work though (in AS3 anyways). I ended up writing my own functions to convert an Array (including Nested Array) into a String, and back from a String into an Array (possibly a Nested Array). This seems to be the easiest way to store data as a nested array.

0 Likes 0 ·
brendan avatar image brendan austerepeasant commented ·

Yes, my example wouldn't work for all languages, granted. Glad to hear you've got it working, now.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.