Question about saving state with SaveStateJSON

0 favourites
  • 4 posts
From the Asset Store
State Machine
$10.99 USD
State Machine is a great tool for managing the state of anything in your game.
  • I want to save the state into an array, so when you press the save button it will save the state, upon save complete I save it to a dictionary.

    The problem is that every time the "save button" is pressed, it pauses, and the pause length increases with each press (you can see this by the spinning fan - it keeps pausing). Eventually, with enough presses, it crashes.

    Any idea why?

    The cp3 file:

    1drv.ms/u/s!AobC4q3rBlr6x_MRlQAFzz925Mj-zA

  • each time you click the save button, the state now includes the contents of the dictionary, so the size of the new state is much larger then the previous click.

    where you show the dictionary.AsJSON, I changed to len(Dictionary.AsJSON) & ": " & Dictionary.AsJSON

    it goes from about 1k on the first click, to about 7k on the second click, to 30K, 151K, 800k...

    I tried adding a Clear Dictionary action before you do the Save, and still grew in size very quickly. Not sure if that is a bug in C3 or not...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • each time you click the save button, the state now includes the contents of the dictionary, so the size of the new state is much larger then the previous click.

    where you show the dictionary.AsJSON, I changed to len(Dictionary.AsJSON) & ": " & Dictionary.AsJSON

    it goes from about 1k on the first click, to about 7k on the second click, to 30K, 151K, 800k...

    I tried adding a Clear Dictionary action before you do the Save, and still grew in size very quickly. Not sure if that is a bug in C3 or not...

    I initially thought that too (since it made sense), but I tried clearing the dictionary and it didn't change, so I figured that wasn't it.

    Thanks so much!

  • Text object is also saved. That's why saving takes longer time with each click, even if you clear the dictionary.

    You can add an object (like an invisible sprite) with NoSave behavior, and store the SaveStateJSON in its instance variable.

    You can go even further - store Dictionary.AsJSON in this sprite's instance variable. Clear the dictionary before saving, then save, then on Save Complete load the dictionary from the sprite and add a new SavedStateJSON record in it.

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