Persistent Data Fix

Discussion in 'Mod Submissions' started by marc1967, Jan 11, 2018.

Remove all ads!
  1. marc1967

    marc1967 Established Member

    Joined:
    Jan 19, 2014
    Messages:
    578
    Likes Received:
    60
    I just found a major problem in the Persistent Data system that could be upsetting to new games.

    Persistent data stays in memory until the program is fully shut down. So if you quit your current game (but don't shut the program itself down), then start a fresh new game, the existing persistent will still be in the system with the new game. The problem arises when you do your first save for the new game, because it will include all the persistent data from the old game.

    I can imagine this has mucked up quite a few fresh games, with dozens of flags and timed events set at the start of a fresh game.

    Recommend completely shutting down TOEE before starting a new game.
     
  2. marc1967

    marc1967 Established Member

    Joined:
    Jan 19, 2014
    Messages:
    578
    Likes Received:
    60
    I don't know what percent of peoples games this has totally thrown out the window, but there could be a quick fix that checks for any persistent data lurking in memory and zeros it all out before play starts. Maybe in the shop map or somewhere early on.
     
  3. marc1967

    marc1967 Established Member

    Joined:
    Jan 19, 2014
    Messages:
    578
    Likes Received:
    60
    Here's the fix, it's very short:

    In /co8Util/PersistentData.py, add a new function called clearData() to the class Co8PersistentData.

    Code:
    def clearData():
        """Clear all data entries"""
        Co8PersistentData.__dataDict.clear()
    clearData = staticmethod(clearData)
    

    Then in py00334generic_spawner.py, where the first_heartbeat occurs in the Shop Map, the line marked by the comment is added.

    Code:
    elif (attachee.map == 5107):
    # shop map
        money_script()
        shopmap_movie_check()
        Co8PersistentData.clearData()   # clears persistent data
    return RUN_DEFAULT
    

    You alse need this at the top of py00334generic_spawner.py.

    Code:
    from co8Util.PersistentData import *
    from co8Util.ObjHandling import *
    

    It all seems to work just fine, and the only other thing that might be added as a safeguard is a global_flag to mark that the data has been cleared, just in case someone makes it back to the Shop Map and the first_heartbeat triggers again.

    Should I include the files?
     
  4. Shiningted

    Shiningted I want my goat back Administrator

    Joined:
    Oct 23, 2004
    Messages:
    12,651
    Likes Received:
    350
    Great work Marc. I only tried to use persistent data once (for a Mass Enlarge spell) and couldn't get my head around it.
     
  5. Endarire

    Endarire Ronald Rynnwrathi

    Joined:
    Jan 7, 2004
    Messages:
    953
    Likes Received:
    112
    Aye! Include the files!

    This seems like a very handy Co8 and T+ inclusion should these be relevant there!
     
Our Host!