How do I load multiple arrays/dictionaries using AJAX plug in?

0 favourites
  • 5 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hi y'all!

    I'm saving my variables such as player inventory, player attributes, experience table, monsters description (loot, gold drop, etc) and I'm using the AJAX plug in to load them.

    I work with multiple layouts, so everytime a layout starts or is suspended/closed, I have to load/save the new infos into the arrays. I have json files for every array/dictionary and save it there.

    Everything was going well, until I add the new player inventory array. I have a variable AJAX_Loading to check if everything was loaded, and exactly on this new array, it's crashing up. If I delete this, it starts working. Also, if I clean the local storage, it works, but for once only. Then, when I save it changing or suspending the layout, the next time, it won't load.

    So, does anybody have any clue on what is going on here? What am I doing wrong?

    Here is my code:

    Thank you so much for your help! :)

  • Saving and loading instance variables between layouts is not really standard practice, you should use global variables or a global player object.

  • Lionz is correct, you shouldn't have to load/save between layouts...

    the reason you are having trouble is that the AJAX loads are only happening if the local storage item is missing. That is why it works one time after clearing local storage. Right after that the item is missing so it executes the AJAX code. Once the inventory is saved to local storage it is no longer missing, so then the AJAX call does not get made, and the AJAXLoading_1 variable will not get set.

    Also, you do not need to do a Get Item after a Check item exists action. If the item exists then the LocalStorage.ItemValue is already set with the stored value, so there is no need to then issue the Get item action. The way you are doing it will work but has to load the item twice for each array.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Got it, guys!

    But my point is, is too much global variables to save and load everytime, also the arrays and dictionaries is way easier to refer to, where I can find values based on a (x,y) from the matrix.

    Also, my game has no animated layouts, is all based on actions that you call from a menu, so there is no global objects such as the player’s character, or npcs, monsters, etc.

    Question 1: If dictionaries and arrays are not the recommended plug in to use, what should I do?

    Question 2: How can I load an array/dic value twice, as you said AllanR?

    Thank you again! :)

  • for question 1, arrays and dictionaries are global by default, so you can access them from any layout.

    I don't understand question 2. When I said you were loading them twice I meant you were reading them from local storage twice - once with the "Check if item exists", and then again with the "Get item" action.

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