How do I locally save an array populated by an AJAX file?

0 favourites
  • 6 posts
From the Asset Store
Source code, art assets and music tracks to remake this game
  • Hey gang!

    Please help :)

    I have an array (called ArrayAIStats), populated by an array file (called Stats.json).

    On start of layout — AJAX| Request Stats.json (tag "")

    AJAX| On "" completed — ArrayAIStats| Load from JSON string AJAX.LastData

    This works totally awesomely. I have a visual array graph, where I can easily change and add values.

    The problem, however, is the values in this array change throughout the game; the stats change. I can't seem to get my local storage save function to save this array in particular; it always resets back to the default values. I'm not sure if it's because the data is being pulled from the Stats.json file? I have a different array that saves, and loads perfectly fine, even as new data gets added onto it. I'm not sure where I'm going wrong :(...

    I attached some screenshots; one of my 'Local Storage' event sheet, the other is of the event sheet for my ArrayAIStats. In my Local Storage event sheet, I underlined in red the array that's giving me problems.

    Thanks in advance!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Looks like the screenshots are from two different event sheets which is concerning. Depends on the order of events, can't tell from these screenshots. From what I can see loading that AJAX request doesn't depend on if you already have save data so it would always run it. My best guess is that you could be loading correctly from local storage then overwriting with the AJAX request.

  • Looks like the screenshots are from two different event sheets which is concerning. Depends on the order of events, can't tell from these screenshots. From what I can see loading that AJAX request doesn't depend on if you already have save data so it would always run it. My best guess is that you could be loading correctly from local storage then overwriting with the AJAX request.

    Heya lionz! Yes, the screenshots are from two different event sheets, as mentioned :)

    First screenshot is of my local storage event sheet.

    The second screenshot is for my array event sheet, which is populating it's data from the AJAX request.

    ^ I included this one because I also have a hunch that the AJAX request is messing things up. The local storage could definitely be getting overwritten by the AJAX request. Any idea how to fix it? LOL

  • If that is happening I would move the AJAX request to a 'local storage save is missing' condition, not 'on start of layout'. So the flow is only to check if your save exists, if it doesn't then load those default values and if it does then load the save data.

  • If that is happening I would move the AJAX request to a 'local storage save is missing' condition, not 'on start of layout'. So the flow is only to check if your save exists, if it doesn't then load those default values and if it does then load the save data.

    You, my friend, are a godsend. This worked perfectly! It's always the littlest of things give you the biggest hiccups, I swear. Thanks Lionz!! After hours spent finagling my local storage issues, you made my day!

  • > If that is happening I would move the AJAX request to a 'local storage save is missing' condition, not 'on start of layout'. So the flow is only to check if your save exists, if it doesn't then load those default values and if it does then load the save data.

    You, my friend, are a godsend. This worked perfectly! It's always the littlest of things give you the biggest hiccups, I swear. Thanks Lionz!! After hours spent finagling my local storage issues, you made my day!

    Nice, that's good :) It was a challenge to work it out from just the screenshot.

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