[RGSS3] Object Reinitializer

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by Zalerinian, Sep 26, 2013.

  1. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    923
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    This script attempts to fix many issues that were caused by loading an old save when new scripts were installed. This script is NOT foolproof, but it will prevent a large number of errors from occurring.

    Warning: Several issues with this script have been identified. There is currently no fix for it, and no ETA on when a new one will be available, but some bits of data, such as player equips will be lost.

    Get the reinitializer on my archive. Current Version: 1.0.2

    Installing the script

    To install this script, place it in the materials section.

    Configuration

    This script does not have any configuration options.

    [​IMG]

    Additional Information

    None

    Version History

    V 1.0.2

    Made followers reinitialize completely, fixing any bugs when adding variables into Game_CharacterBase or Game_Character

    Did the same for Game_Actors to fix any errors from changes in Game_BattlerBase or Game_Battler
    V 1.0.1

    Fixed a bug where followers would stop following the player after loading a save.
    V 1.0.0

    Initial release.
     
    Last edited by a moderator: Dec 28, 2014
    #1
    Archeia, Chaos17, DerTraveler and 2 others like this.
  2. seita

    seita Donn_M Veteran

    Messages:
    2,255
    Likes Received:
    611
    Location:
    California
    First Language:
    English
    About time you slow useless good for noth-

    nice job~!
     
    #2
  3. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,069
    Location:
    Toronto
    First Language:
    English
    Looks good. Simply create a new object and transfer existing data over from the save data to make sure everything exists.
     
    Last edited by a moderator: Sep 26, 2013
    #3
  4. estriole

    estriole Veteran Veteran

    Messages:
    1,030
    Likes Received:
    334
    First Language:
    indonesian
    nice one. this will help for one who already have save in the middle of the game and too lazy to change the starting point (and alter switch and variable).
     
    #4
    Oriceles likes this.
  5. DerTraveler

    DerTraveler Veteran Veteran

    Messages:
    48
    Likes Received:
    38
    Location:
    Osaka, Japan
    First Language:
    German
    Nice script and simple solution...

    What was the original problem? New methods and instance variables of classes modified by scripts that the unmarshalled object doesn't have?

    And what about objects that have other objects as instance variables? Like $game_actors, $game_troop etc.? Won't there be problems when having a script that modifies the Game_Actor or Game_Enemy classes etc.?
     
    #5
  6. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    923
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    That's essentially it. New scripts added expect certain data to be there, but the save file doesn't have it, the new script goes to use it, and it can't work properly and, usually, ends up crashing the game.

    How it works

    Before the save file is actually loaded, goes through its contents, and for each set of data, it will create a new object (unless that set of data is something that can't make a new object, like true or false) of the same type (Game_Player, Game_Map, etc), and this new object will have all the information that the new scripts would have put in there by default. Then, before we're done, we take the information that was in the save file, and put those into the new objects, which are then put back into the save file's data.

    The actual file is not modified unless they save over it again.

    Edit:

    and no, those variables are fine. Those are what are being modified, actually. The script will go through each data set in the save file (by default all the Game_whatever scripts except for a few of them), and then make a new one of those (with the new scripts affecting them). Then, all the values from the old one will be copied over to the new one, making it so that anything a new script adds will be there, while data from the save will be kept as well.

    I suppose that if a scripter changes the type of data stored in a variable that already exists (not exactly a good idea, unless it's for a very specific reason), then this shouldn't have any issues.
     
    Last edited by a moderator: Sep 27, 2013
    #6
  7. ShinGamix

    ShinGamix DS Style 4Ever! Veteran

    Messages:
    3,906
    Likes Received:
    448
    Location:
    Alien Ship
    First Language:
    April Fools
    Primarily Uses:
    N/A
    Wow I am impressed here this will help me out a million tiles a year.

    - I needed this just about 5 mins ago.

    just had added oc-animated gauges

    tried the continue I had used and it nil errored

    then started new game it worked fine.

    SO what's this script suposed to do?
     
    Last edited by a moderator: Sep 29, 2013
    #7
  8. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    923
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    What script are you using?
     
    #8
  9. ShinGamix

    ShinGamix DS Style 4Ever! Veteran

    Messages:
    3,906
    Likes Received:
    448
    Location:
    Alien Ship
    First Language:
    April Fools
    Primarily Uses:
    N/A
    I am using a lot of scripts (50+)in my project and they all run fine with no errors.

    (I have had extensive testing done)

    but I had wanted to use a previous continue as your script said it allowed.
     
    #9
  10. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    923
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    Sorry for the very late reply, I've been very busy, what is the exact error it's giving you?
     
    #10
  11. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    923
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    The script has been updated to V 1.0.1 to fix a bug where followers would stop following the player after you load a save.
     
    Last edited by a moderator: Jan 2, 2014
    #11
    Chaos17 likes this.
  12. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,967
    Location:
    Philippines
    First Language:
    Tagalog
    btw, how about the values for those things? especially those that load data from notetags...
     
    #12
  13. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    923
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    If the data is stored in an instance variables (anything starting with a single '@'), then it will be copied over to the new object.

    Edit: All other data is left as it is when a new instance of a class is created. The game's followers, though, are re-modified so that they continue to follow the leader (the first follower's @preceding_character must be set to the proper instance of the Game_Player class, or else they'd stop moving after the first step in a loaded file.
     
    Last edited by a moderator: Jan 3, 2014
    #13
    Engr. Adiktuzmiko likes this.
  14. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    923
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    Version 1.0.2 has been uploaded that should fix any issues with followers or actors having issues with new scripts expecting variables (even if you don't use followers, RM will till update them and cause potential errors). This script is NOT foolproof, and some scripts may still error, due to when it tries to access a certain variable (if a new variable is expected when running initialize but was not created before the method was called most likely will crash, regardless of this script), so please do not expect this script to fix any save file issue.
     
    #14
  15. seita

    seita Donn_M Veteran

    Messages:
    2,255
    Likes Received:
    611
    Location:
    California
    First Language:
    English
    10/10 would break again so he can fix it. Works like a charm after each fix~
     
    #15
    Zalerinian likes this.
  16. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,069
    Location:
    Toronto
    First Language:
    English
    Is there a particular reason why you chose to copy values from the saved objects into the newly initialized objects, rather than copying values from the newly initialized objects into the saved objects?
     
    #16
    Zalerinian likes this.
  17. Zalerinian

    Zalerinian Jack of all Errors Veteran

    Messages:
    4,695
    Likes Received:
    923
    Location:
    The Internet.
    First Language:
    English
    Primarily Uses:
    N/A
    When I first made it, my thinking was that copying the old into the new would ensure all the old data exists while any new data was created. Now, though, I suppose I should be able to easily copy the new into the old by comparing the two values and seeing which ones exist in the new but not the old, and only take those. I'll test some new methods and see what seems to be the best.

    Edit:

    Thinking a bit more about that now, I don't think just copying values from the old into the new will work so much because things like the followers will not work again.
     
    Last edited by a moderator: Dec 28, 2014
    #17
  18. Tsukihime

    Tsukihime Veteran Veteran

    Messages:
    8,230
    Likes Received:
    3,069
    Location:
    Toronto
    First Language:
    English
    You mentioned the follower issue in another topic but I'm still confused about why it's a problem.

    We're sure the default loading process works: followers are following the player correctly as they were when the game was saved.

    When you add some logic to copy new data over to "patch up" the old save file, the followers would (or should) still be referencing the same player object (which is the one retrieved from the save file).

    Basically, the player that's passed into the followers array should be equal to $game_player

    class Game_Player def initialize super @vehicle_type = :walk # Type of vehicle currently being ridden @vehicle_getting_on = false # Boarding vehicle flag @vehicle_getting_off = false # Getting off vehicle flag @followers = Game_Followers.new(self) @transparent = $data_system.opt_transparent clear_transfer_info endclass Game_Followers def initialize(leader) @visible = $data_system.opt_followers @gathering = false # Gathering processing underway flag @data = [] @data.push(Game_Follower.new(1, leader))It's just the $game_player reference being tossed around.If the serialization process actually breaks this reference (perfectly possible) such that the first follower isn't following $game_player anymore...then I'm wondering how the default scripts work. There doesn't appear to be any special handling after the save file is loaded where the follower's leader is updated or anything.

    EDIT: my post shouldn't belong in a script release thread so I've made another topic about it here: http://forums.rpgmakerweb.com/index.php?/topic/35329-patch-old-save-files-with-new-data
     
    Last edited by a moderator: Dec 28, 2014
    #18

Share This Page