Is the "save game" action synchronous or async?

Not favoritedFavorited Favorited 0 favourites
  • 6 posts
From the Asset Store
HTML5 Game Bundle (7 Games) – Created with Construct 3
  • I have a weird bug I'm experiencing, but I don't quite know how I'd go about reproducing it for the official bug submission process, so I'm starting with some theories about what I'm doing that might be wrong.

    I have a settings menu in my game that can be accessed from any layout. Returning from this menu must put you right back where you came from, so I use the built-in save/load functions to restore the state of the level you were in previously.

    Here are what my functions look like:

    Function goToMenu(string menu)

    • Save game to slot "menu"
    • Take snapshot of canvas (this is so the settings menu appears on top of the level)
    • Wait for previous actions to complete
    • Go to layout menu

    Function returnFromMenu()

    • Load game from slot "menu"
    • (Other async stuff)
    • Wait for previous actions to complete

    So my question is this - stuff like "Take snapshot" and my "other async stuff" are async actions that can be waited on with "Wait for previous actions to complete". But, can I guarantee that the game will be fully saved by the time goToMenu() ends?

    I'm aware of the "On save complete" action, but I really wish I could use the async features to make it easy to tell which save event is which (I also use the same save system for in-level checkpoints).

  • In case anyone just so happens to recognize the error I'm dealing with, here's the most common offending stacktrace.

    This sporadically happens when I'm returning from the menu (yes, there are some instances in the layout with the Tween behavior).

    runtime.js:1 [Construct] Failed to load state from storage: Error: cannot call while loading state - wait until afterload event at C3.Runtime.GetInstanceByUID (runtime.js:1:49355) at C3.TweenTrackState.GetInstance (trackState.js:1:2663) at C3.TweenState.GetInstance (tweenState.js:1:1636) at C3.TweenState._TweenTrigger (tweenState.js:1:10306) at C3.TweenState.Release (tweenState.js:1:580) at s.Instance.ReleaseTweens (runtime.js:1:7451) at s.Instance.ReleaseAndCompleteTweens (runtime.js:1:7684) at s.Instance.Release (runtime.js:1:1063) at C3.BehaviorInstance.Release (behaviorInstance.js:1:538) at C3.Instance.Release (instance.js:1:1836)

  • I believe both Save and Load actions are async. You need to use "On Save complete" and "On Load complete" triggers to perform additional actions. For example:

     ---> Load game from "Menu"
    
    On Load complete
     ---> Call LoadGame function
    
  • Darn, I was afraid of that.

    Does anyone know why they don't support the async functionality and "Wait for previous actions"?

  • For the "Load" action it won't make sense, because the game may be loaded in a completely different layout. Any code you have after "Wait for previous action" would be ignored anyway.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh, that's good to know! I wasn't sure whether that was the case.

    I tried waiting for the "On save complete" event to fire before going to the other layout, so it seems as if saving isn't the problem.

    I've also been digging further into the devtools debugger for error I'm getting. It seems as if `runtime._DoChangeLayout()` is failing inside `runtime._ReleasePendingInstances()`, such that `runtime._isLoadingState` never gets changed back to `false`.

    Furthermore, after the error happens, all of the instances getting released in this loop `for (const e of this._instancesPendingRelease) e.Release()` have `e._objectType == null`. Obviously since the code is a) not mine, and b) minified, I'm not sure what to make of this.

    I also don't know how I'd go about posting a bug report since I can't get this error to reproduce in a minimal project, and I don't know how I can find what specific thing in my project might be causing this (that would need to be recreated in the minimal project).

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