Save array to dictionary?

0 favourites
  • 11 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • How do i save Array data to dictionary?

    I have this array I need to save to either dictionary or local storage and then I need it to spit out json

    that a plugin(airconsole) can read and store data on their servers. Im not sure if i explained that correctly?

    Is this right?

  • Hi, theoretically it's possible but I don't see much use here...

    A painting is what?, a kind of grid in 1, 2 or 3 dimensions...

    Dimension 1 = X or Y (I don't know), dimension 2 = Same, dimension 3 = depth (imagine a cube)

    A dictionary is what? a kind of 2-dimensional table (1x2 or 2x1 = X rows, 2 columns), the first dimension contains the key, the second dimension contains the value.

    Go through your table (each element), dimension by dimension, create a key on your dictionary, then put the value of your table (value currently read) in it.

    For the key, it is up to you to see what you want to put, you can for example either put a key that represents the position in your array, or meter a key that is equal to the value of your array.

    Here is an example:

    Your table 1 dimension -> MyTable(2) = 2 possible values

    MyTable(0) = "abc"

    MyTable(1) = "def"

    MyTable(2) = "ghi"

    Your dictionary -> MyDictionary()

    MyDictionary() = Key: "0", Value: "abc"

    MyDictionary() = Key: "1", Value: "def"

    MyDictionary() = Key: "2", Value: "ghi"

    Or like this:

    MyDictionary() = Key: "abc", Value: "abc"

    MyDictionary() = Key: "def", Value: "def"

    MyDictionary() = Key: "ghi", Value: "ghi"

    Have I made myself clear?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks. I'll work on this later and see if I can figure it out.

    So can the dictionary be used to control level selection screen? I'm using the array 1=unlocked 2=1 star 3=2stars 4=3stars. So on level complete if player gets all 3 stars it sets the value at that level to 4.

    I wrote the level select screen a long time ago and it worked with webstorage but I honestly can't remember why I did what I did so I'd like to redo it.

  • Would it work a key for every level?

    So 10 levels

    Key level1=0 then a player wins with all three stars I set to

    Key level1=4?

    Not sure I'm understanding correctly

  • I'm having trouble following you, do you really need a dictionary?

    A dictionary is very useful to instantly access a specific value using the key.

    In a dictionary, to search for a value, you simply enter the name of the key.

    In a table you have to do the search 1 by 1 until you have found it.

    I suggest you make a small simple example to understand what you want to do, then I will help you, there I don't know what to do.

    Have you understood the usefulness of a dictionary?

    E.g.: "Car" dictionary, each element will contain a key that is the name of the car, then a value that is its price, okay?

  • Okay thanks ill try and put together an example. The reason I think I need to use dictionary is because im trying to save persistant data to airconsole servers. So i have my Levels array which works perfect for displaying what level is unlocked and how many stars a player got. However this is what the airconsole plugin says

    (AIRCONSOLE).PERSISTENTDATA

    Description: Returns a JSON string representation of the persistent data loaded by the last requestPersistentData. Use C2Dictionary.Load to grab/traverse the data

    Loaded by: onPersistentDataLoaded

    Can be used after: OnPersistentDataLoaded

    it says c2 but the plugin works on c3 the documentation hasnt been updated i believe.

  • Une variable ne fonctionne pas ?

    Ouais, une variable par niveau pas top c'est sur... ok.

    Ok donc dans ton dico, dis moi se que tu dois exactement stoker.

    Tu peu stoker par élément une clef et une valeur.

    Ex: Clef: "Niveau 1", Valeur = 3 (tu peux aussi stoker une chaîne de caractères)

    Ex: Clef: "Niveau 1", Valeur = "3"

    C'est ultra rapide comme méthode le dico !

    Bien plus rapide pour retrouver un élément que dans un tableau !

    Est ce que ça t'aide, au pire fais un petit exemple que je le vois et t'aide.

  • The translation is making this even harder to understand im so sorry! Thank you for trying to help me though I think some words are being translated wrong. So here is an example of my level selection screen.

    I cant get localstorage to store the array data not sure what im doing wrong there.

    Also I have included the airconsole plugin. I would like to save the array to the airconsole persistent servers. if you cant help with that I understand.

    https://www.dropbox.com/s/l95fng0azyvc67k/Example.c3p?dl=0

  • LonelyPear You are using Local Storage wrong. You can't just execute "Local Storage Get" and assume that it will read data from local storage and put it into your array. I made a few changes in your project, see comments in yellow:

    dropbox.com/s/gs7b5jfeydm586z/array_ls.c3p

    .

    If you need to save a dictionary in local storage, it's done the same way - to save "Set item to Dictionary.AsJSON", to restore "Check item exists, if exists, load dictionary fron LocalStorage.ItemValue"

  • Lol.. Honestly I only know halfway what im doing as you can see.

    So here i was trying to have the webstorage reset so i can test it multiple times. I changed it to remove item but that didn't achieve what I thought it would. I figured out what i should have been doing was clearing the array >.< It works though thank you!

    Here i was attempting to save the array as a dictionary I dont know much about json or how to use it so im sure its all wrong. I think i need to use the dictionary for the airconsole plugin but I really have no clue

    This is the plugin for saving persistent data but i couldnt find any tutorials on how to save and load using it. So if anyone has any experience with airconsole help would be greatly appreciated :)

  • Create a blank project, add an array, dictionary and Browser object.

    Add some values to the array, some keys to dictionary, add actions:

    Browser Log Array.AsJSON

    Browser Log Dictionary.AsJSON

    Run the project, press F12 and see console messages. This will help you to understand what is JSON and how it works.

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