Script 'Persistent Data' - error with Debug Menu

● ARCHIVED · READ-ONLY
Started by tvghost 8 posts View original ↗
  1. The only available versions I see of the script is through these two links - the script author is Fomar0153:
    1. https://aveyond.com/forums/index.php?/topic/15048-need-helpexplanation-with-this-script/
    2. https://steamcommunity.com/sharedfiles/filedetails/?l=english&id=230899119
    Error description: It seems that the game bugs when trying to scroll through the variable section of the debug menu. Putting the number of switches above 100 causes this error pop up:
    upload_2018-9-30_22-33-16.png
    If you put your switch limit to 111 or anything that's less than 200, this happens:
    upload_2018-9-30_22-33-59.png
    Demo attached below. Here are the areas I think are causing the issue:
    upload_2018-9-30_22-26-47.png
    In the Persistent Data script (specifically the $game_persistentvariables)
    upload_2018-9-30_22-27-46.png
    In Window_DebugLeft.
  2. It just wasn't written with the debug window in mind, expecting only switches/variables that exist to be referenced.

    Try replacing it with this:
    Spoiler
    Code:
    =begin
    Persistent Data
    by Fomar0153
    Version 1.0
    ----------------------
    Notes
    ----------------------
    Allows you to preserve the values of selected variables
    and switches across all games.
    ----------------------
    Instructions
    ----------------------
    If you wish adjust the strings in the Fomar module.
    Then put the PERSISTENT_DATA_STRING in to the names of
    the switches or variables that are to be persistent.
    E.g.
    [p]Talked to mayor
    Case 1: Progress [p]
    ----------------------
    Known bugs
    ----------------------
    None
    =end
    
    module Fomar
    
     # Enter the string below into the names of the switches or variables
     # that are to be persistent
     PERSISTENT_DATA_STRING = "[p]"
     # DO NOT USE SAVE in the string below
     PFILENAME = "PersistentData.rvdata2"
    
    end
    
    class Game_PersistentSwitches
     #--------------------------------------------------------------------------
     # * Object Initialization
     #--------------------------------------------------------------------------
     def initialize
       @data = {}
     end
     #--------------------------------------------------------------------------
     # * Get Switch
     #--------------------------------------------------------------------------
     def [](switch_id)
       @data[switch_id] || false
     end
     #--------------------------------------------------------------------------
     # * Set Switch
     #     value : ON (true) / OFF (false)
     #--------------------------------------------------------------------------
     def []=(switch_id, value)
       @data[switch_id] = value
       DataManager.save_persistent
     end
    end
    
    class Game_PersistentVariables
     #--------------------------------------------------------------------------
     # * Object Initialization
     #--------------------------------------------------------------------------
     def initialize
       @data = {}
     end
     #--------------------------------------------------------------------------
     # * Get Variable
     #--------------------------------------------------------------------------
     def [](variable_id)
       @data[variable_id] || 0
     end
     #--------------------------------------------------------------------------
     # * Set Variable
     #--------------------------------------------------------------------------
     def []=(variable_id, value)
       @data[variable_id] = value
       DataManager.save_persistent
     end
    end
    
    class Game_Switches
     #--------------------------------------------------------------------------
     # * Get Switch
     #--------------------------------------------------------------------------
     def [](switch_id)
       if $data_system.switches[switch_id] && $data_system.switches[switch_id].include?(Fomar::PERSISTENT_DATA_STRING)
         return $game_persistentswitches[switch_id]
       else
         return @data[switch_id] || false
       end
     end
     #--------------------------------------------------------------------------
     # * Set Switch
     #     value : ON (true) / OFF (false)
     #--------------------------------------------------------------------------
     def []=(switch_id, value)
       if $data_system.switches[switch_id] && $data_system.switches[switch_id].include?(Fomar::PERSISTENT_DATA_STRING)
         $game_persistentswitches[switch_id] = value
       else
         @data[switch_id] = value
       end
       on_change
     end
    end
    
    class Game_Variables
     #--------------------------------------------------------------------------
     # * Get Variable
     #--------------------------------------------------------------------------
     def [](variable_id)
       if $data_system.variables[variable_id] && $data_system.variables[variable_id].include?(Fomar::PERSISTENT_DATA_STRING)
         return $game_persistentvariables[variable_id]
       else
         return @data[variable_id] || 0
       end
     end
     #--------------------------------------------------------------------------
     # * Set Variable
     #--------------------------------------------------------------------------
     def []=(variable_id, value)
       if $data_system.variables[variable_id] && $data_system.variables[variable_id].include?(Fomar::PERSISTENT_DATA_STRING)
         $game_persistentvariables[variable_id] = value
       else
         @data[variable_id] = value
       end
       on_change
     end
    end
    
    module DataManager
     #--------------------------------------------------------------------------
     # * Aliases
     #--------------------------------------------------------------------------
     class << self
       alias persistent_create_game_objects create_game_objects
       alias persistent_load_game load_game
     end
     #--------------------------------------------------------------------------
     # * Execute Load
     #--------------------------------------------------------------------------
     def self.load_game(index)
       self.load_persistent
       return self.persistent_load_game(index)
     end
     #--------------------------------------------------------------------------
     # * Create Game Objects
     #--------------------------------------------------------------------------
     def self.create_game_objects
       self.persistent_create_game_objects
       self.load_persistent
     end
     #--------------------------------------------------------------------------
     # * Save Persistent Data
     #--------------------------------------------------------------------------
     def self.save_persistent
       begin
         File.open(Fomar::PFILENAME, "wb") do |file|
           persistent = {}
           persistent[:switches] = $game_persistentswitches
           persistent[:variables] = $game_persistentvariables
           Marshal.dump(persistent, file)
         end
       rescue
         File.delete(Fomar::PFILENAME) rescue nil
       end
     end
     #--------------------------------------------------------------------------
     # * Load Persistent Data
     #--------------------------------------------------------------------------
     def self.load_persistent
       begin
         File.open(Fomar::PFILENAME, "rb") do |file|
           contents = Marshal.load(file)
           $game_persistentswitches  = contents[:switches]
           $game_persistentvariables = contents[:variables]
         end
       rescue
         $game_persistentswitches  = Game_PersistentSwitches.new
         $game_persistentvariables = Game_PersistentVariables.new
         self.save_persistent
       end
     end
    end
  3. please make sure that your script slots are correctly named.
    having one of the slots still with the name "insert here" is bad for later bughunting.
    Please give every slot a name that tells which script is there
  4. Andar said:
    please make sure that your script slots are correctly named.
    having one of the slots still with the name "insert here" is bad for later bughunting.
    Please give every slot a name that tells which script is there
    You really have a problem with me, huh.
    For the sake of a demo with only *one* third party script, this is a non-issue.
  5. Shaz said:
    It just wasn't written with the debug window in mind, expecting only switches/variables that exist to be referenced.

    Try replacing it with this:
    Spoiler
    Code:
    =begin
    Persistent Data
    by Fomar0153
    Version 1.0
    ----------------------
    Notes
    ----------------------
    Allows you to preserve the values of selected variables
    and switches across all games.
    ----------------------
    Instructions
    ----------------------
    If you wish adjust the strings in the Fomar module.
    Then put the PERSISTENT_DATA_STRING in to the names of
    the switches or variables that are to be persistent.
    E.g.
    [p]Talked to mayor
    Case 1: Progress [p]
    ----------------------
    Known bugs
    ----------------------
    None
    =end
    
    module Fomar
    
     # Enter the string below into the names of the switches or variables
     # that are to be persistent
     PERSISTENT_DATA_STRING = "[p]"
     # DO NOT USE SAVE in the string below
     PFILENAME = "PersistentData.rvdata2"
    
    end
    
    class Game_PersistentSwitches
     #--------------------------------------------------------------------------
     # * Object Initialization
     #--------------------------------------------------------------------------
     def initialize
       @data = {}
     end
     #--------------------------------------------------------------------------
     # * Get Switch
     #--------------------------------------------------------------------------
     def [](switch_id)
       @data[switch_id] || false
     end
     #--------------------------------------------------------------------------
     # * Set Switch
     #     value : ON (true) / OFF (false)
     #--------------------------------------------------------------------------
     def []=(switch_id, value)
       @data[switch_id] = value
       DataManager.save_persistent
     end
    end
    
    class Game_PersistentVariables
     #--------------------------------------------------------------------------
     # * Object Initialization
     #--------------------------------------------------------------------------
     def initialize
       @data = {}
     end
     #--------------------------------------------------------------------------
     # * Get Variable
     #--------------------------------------------------------------------------
     def [](variable_id)
       @data[variable_id] || 0
     end
     #--------------------------------------------------------------------------
     # * Set Variable
     #--------------------------------------------------------------------------
     def []=(variable_id, value)
       @data[variable_id] = value
       DataManager.save_persistent
     end
    end
    
    class Game_Switches
     #--------------------------------------------------------------------------
     # * Get Switch
     #--------------------------------------------------------------------------
     def [](switch_id)
       if $data_system.switches[switch_id] && $data_system.switches[switch_id].include?(Fomar::PERSISTENT_DATA_STRING)
         return $game_persistentswitches[switch_id]
       else
         return @data[switch_id] || false
       end
     end
     #--------------------------------------------------------------------------
     # * Set Switch
     #     value : ON (true) / OFF (false)
     #--------------------------------------------------------------------------
     def []=(switch_id, value)
       if $data_system.switches[switch_id] && $data_system.switches[switch_id].include?(Fomar::PERSISTENT_DATA_STRING)
         $game_persistentswitches[switch_id] = value
       else
         @data[switch_id] = value
       end
       on_change
     end
    end
    
    class Game_Variables
     #--------------------------------------------------------------------------
     # * Get Variable
     #--------------------------------------------------------------------------
     def [](variable_id)
       if $data_system.variables[variable_id] && $data_system.variables[variable_id].include?(Fomar::PERSISTENT_DATA_STRING)
         return $game_persistentvariables[variable_id]
       else
         return @data[variable_id] || 0
       end
     end
     #--------------------------------------------------------------------------
     # * Set Variable
     #--------------------------------------------------------------------------
     def []=(variable_id, value)
       if $data_system.variables[variable_id] && $data_system.variables[variable_id].include?(Fomar::PERSISTENT_DATA_STRING)
         $game_persistentvariables[variable_id] = value
       else
         @data[variable_id] = value
       end
       on_change
     end
    end
    
    module DataManager
     #--------------------------------------------------------------------------
     # * Aliases
     #--------------------------------------------------------------------------
     class << self
       alias persistent_create_game_objects create_game_objects
       alias persistent_load_game load_game
     end
     #--------------------------------------------------------------------------
     # * Execute Load
     #--------------------------------------------------------------------------
     def self.load_game(index)
       self.load_persistent
       return self.persistent_load_game(index)
     end
     #--------------------------------------------------------------------------
     # * Create Game Objects
     #--------------------------------------------------------------------------
     def self.create_game_objects
       self.persistent_create_game_objects
       self.load_persistent
     end
     #--------------------------------------------------------------------------
     # * Save Persistent Data
     #--------------------------------------------------------------------------
     def self.save_persistent
       begin
         File.open(Fomar::PFILENAME, "wb") do |file|
           persistent = {}
           persistent[:switches] = $game_persistentswitches
           persistent[:variables] = $game_persistentvariables
           Marshal.dump(persistent, file)
         end
       rescue
         File.delete(Fomar::PFILENAME) rescue nil
       end
     end
     #--------------------------------------------------------------------------
     # * Load Persistent Data
     #--------------------------------------------------------------------------
     def self.load_persistent
       begin
         File.open(Fomar::PFILENAME, "rb") do |file|
           contents = Marshal.load(file)
           $game_persistentswitches  = contents[:switches]
           $game_persistentvariables = contents[:variables]
         end
       rescue
         $game_persistentswitches  = Game_PersistentSwitches.new
         $game_persistentvariables = Game_PersistentVariables.new
         self.save_persistent
       end
     end
    end
    Solves the issue perfectly. Thank you.
  6. tv.ghost said:
    For the sake of a demo with only *one* third party script, this is a non-issue
    Actually, it's not. I opened your demo and I couldn't find the script. I wondered if you hadn't put it in and was going to come back and ask you to upload it again with the script. It was only by accident that I looked in that particular slot and found it.
  7. Shaz said:
    Actually, it's not. I opened your demo and I couldn't find the script. I wondered if you hadn't put it in and was going to come back and ask you to upload it again with the script. It was only by accident that I looked in that particular slot and found it.
    Fair enough, alright. I'll keep it in mind for future script questions.
  8. [closed]IgnoreMe[/closed]