What might cause an AJAX error in an offline game?

0 favourites
  • 5 posts
From the Asset Store
Use this game pack to create your own game, modify the existing game or simply take a look and see how it was made.
  • For in-game dialog, I like to use separate text files which I load through AJAX at the start of a level, save to an array, and then parse line by line.

    This works perfectly 99.9% of the time.

    But on very rare occasions, the requested text file simply won't load. For my current in-development game, I've added an "on any error" condition so that I can see if a request failure happens in the future, but given how rare and seemingly random the error is, it might be hard to test for. I might go months without seeing the error again.

    Bearing in mind that my game is offline (NW.js) and that I'm not doing something silly with file names or weird file contents, my questions are:

    1. What might cause a file requested through AJAX to return successfully most of the time, but occasionally fail?

    2. Is there an alternative way to load text files that never results in failure?

  • Could you share a screenshot of your events? Just to make sure that you are doing everything correctly.

    I guess you can try a stress-test. Change your code, so that if AJAX loads the file successfully, the game exits. If "On error" is triggered or AJAX.lastdata is empty, display some debug information and don't exit the game.

    Then set up Windows Scheduler to run your game every few seconds. Or create a batch file RunAgain.bat :

    MyGame.exe
    timeout /t 10
    RunAgain.bat
    [/code:c9t5koy0]
  • Sure, here's the important bit of code. Request the file, stick it into an array, then if the level calls for it, immediately call the function that parses the array. I think, when the request fails, "on any completed" doesn't trigger at all.

    A stress test is a good idea. I'll set one up later.

  • You don't have any other AJAX requests or AJAX->"On any completed" in other event sheets?

    I would change "On any completed" to "On 'ScriptLoad' completed" just to be on the safe side.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Right now, AJAX requests are exclusively for dialog, but I might use them for save files in the future, so sure, I'll make that change.

    I'm running a stress test now. I'll update if I can find anything unusual.

    Update:

    After running a test with tens of thousands of AJAX requests, I haven't been able to create a spontaneous error. This is a good thing, I suppose - it means the problem is probably with my code, not with AJAX.

    I did notice one thing - the speed of AJAX completions skyrockets when the window is out of focus, I guess because the game loop is no longer confined to the framerate. Not too surprising.

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