• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

What can cause a "Save Failed"

  • 119
    Posts
    11
    Years
    • Seen Sep 1, 2023
    I was wondering what kind of things can cause the game to fail a save?

    I've just discovered that the project I'm working fails to save every time. In specific situations it succeeds in saving, yet then the game still breaks after loading (giving errors caused by data not being saved correctly). I've made little changes to the save and load scripts; only creating a new variable on new game and saving and loading of this variable. Besides that I've made several changes to the essentials code and added my own systems.

    One of these systems allows the creation of multiple characters (each with their own party, etc.), switching between them, and interaction between characters. The data for all these characters is stored in one variable.

    As a result I have a few questions:
    - Are there certain variable types which should be avoided?
    - Are there size limits or time limits to saving data?
    - What are best practices to pinpoint the cause of failed saves?
    - Could it be caused by something outside the essentials code?

    On a dubious side note: When testing previous versions I noticed it was a problem in all versions which include the system, yet I'm sure I originally was able to use the system without these errors. This would suggest that something outside the code is causing this. To my knowledge this shouldn't be possible.
     
    I was wondering what kind of things can cause the game to fail a save?

    I've just discovered that the project I'm working fails to save every time. In specific situations it succeeds in saving, yet then the game still breaks after loading (giving errors caused by data not being saved correctly). I've made little changes to the save and load scripts; only creating a new variable on new game and saving and loading of this variable. Besides that I've made several changes to the essentials code and added my own systems.

    One of these systems allows the creation of multiple characters (each with their own party, etc.), switching between them, and interaction between characters. The data for all these characters is stored in one variable.

    As a result I have a few questions:
    - Are there certain variable types which should be avoided?
    - Are there size limits or time limits to saving data?
    - What are best practices to pinpoint the cause of failed saves?
    - Could it be caused by something outside the essentials code?

    On a dubious side note: When testing previous versions I noticed it was a problem in all versions which include the system, yet I'm sure I originally was able to use the system without these errors. This would suggest that something outside the code is causing this. To my knowledge this shouldn't be possible.

    Can you show us what you've added to save it? If you're just saving a couple variables, it's far easier to store them in $game_variables or in $PokemonGlobal, then you wouldn't have to make any additions to your code. However it's fairly easy to add data to save, but you have to make sure you load it correctly also.

    If you're saving them as a game_variable, I have had problems with storing arrays and multidimensional arrays there. That could be causing problems for you if you're doing that.

    If your storing it in something else, if you haven't initialized the variable it could also cause it to fail.
     
    Changes in the save and load scripts:

    Code:
    # Added in load below: $PokemonStorage      = Marshal.load(f)
    $CharacterData       = Marshal.load(f)
    
    # Added in load below: $PokemonStorage      = PokemonStorage.new
    $CharacterData       = CharacterData.new
    
    # Added in save below: Marshal.dump($PokemonStorage,f)
    Marshal.dump($CharacterData,f)

    As the code above shows, $CharacterData is a class. This class contains various variables among which dozens of arrays which are used to store data per character. This data includes bag data, trainer data, pokemon storage data, etc. There are also a few multidimensional arrays (such as saving the position of each character).

    I assume the game is able to save variables with a value of nil. If this is not the case I'll have to check all my code.

    How did you manage to store attays and multidimensional arrays? Or should it work if they're variables within a class (stored in $CharacterData)?

    Note: I managed to fix the errors caused by loading the game (the necessary data wasn't saved even if the game saved correctly). This means there weren't any problems when loading the data, yet a part of the data wasn't saved (some variable didn't have a "attr_reader:var_name" at the start of the class).
    Thus right now the game often fails to save. I'm currently running tests to check when the game does and doesn't save successfully.

    EDIT: After some testing the main problem seems to be an empty multidimensional array. I intent to use it for global variables per character, yet it currently creates an empty array per character. The code below shows the current code uses of the variable:
    Code:
    # Inside the class initializtion:
    @variables = []
    
    # Inside the function which creates a new character:
    @variables[id] = []

    I still need to do further testing to make sure this is the source of the saving problem.
     
    Last edited:
    EDIT: After some testing the main problem seems to be an empty multidimensional array. I intent to use it for global variables per character, yet it currently creates an empty array per character. The code below shows the current code uses of the variable:
    Code:
    # Inside the class initializtion:
    @variables = []
    
    # Inside the function which creates a new character:
    @variables[id] = []

    I still need to do further testing to make sure this is the source of the saving problem.

    You can initialize a multi-array much easier, like this
    Code:
    @variables = Array.new(#number_of_characters) { Array.new(#number_of_values_to_be_stored_for_each_character) }
    Declaring multi-arrays like that might not function as you want it to.
     
    Do you mind showing us the whole class CharacterData? Saves fail when you try to dump incorrectly initialized/handled variables. It could be that some defs or variables in your class aren't well made.
     
    Some objects cannot be dumped: if the objects to be dumped include bindings, procedure objects, instances of class IO, or singleton objects, a TypeError will be raised, so take care with what you dump. This occurs notably with a Bitmap object. If you really wish (and know what are you doing), you can serialize these objects for saving and unserialize after loading.
     
    I managed to fix the problem;
    The save fail was caused by the defs which are used to create the character switching menu. The menu is based on the pause menu and pbShowCommands. The variable types FL mentioned got me thinking in the right direction (though I don't exactly know yet what each of those types are exactly). Moving these defs into a different class fixed the saving problem (I don't want these to be saved anyway).

    Thank you all for your replies and help :)

    ps. It also turns out the empty array actually didn't cause any problems. At that point I just happened to use a different test in which I didn´t use the menu. (I know, I didn't use proper bug testing practices at that point XD sorry.)
     
    Back
    Top