SOLVED: Array issue (updated)

0 favourites
  • 5 posts
From the Asset Store
Fantasy Game includes more than 600 sound effects inspired by hit computer games like World of Warcraft and Diablo.
  • After doing some more testing my problem is a little different than I first thought. To avoid confusion I decided to rewrite my question.

    For about a year my game has used an internal .json file for daily puzzle data. Unfortunately, every time I add new content I have to completely re-publish my game, so I thought it would be easier to make the .json file external.

    I removed the internal file and set up a spot on my website for the new file. When I run the game it downloads the .json file and runs. (Without the .json file the game wouldn't work at all.) But it's not downloading the correct file somehow.

    I look at the file that is on my website, and then I print out the AJAX.LastData text and they don't match at all! (They may have matched the first time I uploaded the .json file, but I have been deleting the old files and uploading new ones. It's not downloading the new ones!)

    Anyone know why this might be happening?

    SOLVED: I turned to ChatGPT this morning and explained my problem. As suspected, it suggested a caching issue and provided several solutions. The first thing I tried didn't work (adding some APACHE code to my .httaccess file to prevent the .json file from being cached). But it also proposed that I add a unique query string to my download URL, which DID work:

    "https://worddad.com/download/output.json?v=" & current_date

    I probably need to change "current_date" to a timestamp. I think that variable is just the day, in text format. But this change fixed my problem!!

  • My guess would be to look into the json your website is generating.

    Maybe it’s mistakenly putting a width of 370 but it only contains 342 elements in the array in the json?

    Im guessing the size part of the json is largely ignored when it loads and instead it relies on the size of the data? It’s something you can test.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sounds like a caching issue to me.

    It might be possible that C3 (or any export option) loads the file from local cache. In that case, check your web server's Cache-Control / Expire Header settings. Or any other layer of caching.

    Might be worth checking out.

  • Thank you, Everade. I'm totally clueless about stuff like that. I'll do some research!

  • Looks like it was indeed getting it from a cache. Glad i was able to help.

    Just keep in mind when calling with a parameter like you said:

    https://worddad.com/download/output.json?v=" & current_date

    Will still cache it locally, and also still get it from cache for a max of 24 hours.

    For example if a player starts playing at 01:00 in the morning, and you update the JSON file at 01:30, the player will not get this update (loading the file from local cache) until the next day comes around.

    Which might not be what you want. So a more accurate timestamp including hours/minutes would make sense here.

    However keep in mind that the json files are still cached locally for the duration set by your web server (possibly for a year), even if not needed. Entirely depending on your website's cache settings. Not a big deal, but something to be aware off.

    If you want to truly prevent caching locally, you would have to change the expire header on your webserver.

    This here would disable local cache for all JSON mime types on your website:

    In your .htaccess add:

    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType application/json A0
    </IfModule>
    

    But there might be additional layers of caching, for example if you run your website through a CDN (for example Cloudflare) which may cache files on their cloud systems as well.

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