Random battle music (BGM) without starting new game

There is a good random BGM script here for vx ace:

It works fine if you start a new game. But if I want to add it a game in progress and continue, it causes this error upon starting a battle:
line 142: NoMethodError occurred.
undefined method 'empty?' for nil"NilClass

Line 142 is :
#--------------------------------------------------------------------------
# * Determine if Battle Random BGM's should be used
#--------------------------------------------------------------------------
def use_battle_random_bgm? ; !@battle_random_bgm_disabled and !@battle_random_bgm_list.empty? end

With the amount of random BGMs I added to the settings.

I believe whatever initialization code is run to make it work, only happens on a new game, not on continue. Is there a way I can run that code after a continue or mod the script ot work on continued games (where the script wasnt present at the start)?
Here's "my fixed version" so to say.
(Yeah, it's too long. Take a look at the short version.)

Ruby:
#==============================================================================
# ** TDS Battle Random BGM
#    Ver: 1.0.1
#------------------------------------------------------------------------------
#  * Old Saved Games Fix by Kyonides Arkanthes
#------------------------------------------------------------------------------
#  * Description:
#  This script allows you to set random BGM to play when the battle starts.
#------------------------------------------------------------------------------
#  * Features:
#  Enabling and Disabling Battle Random BGM's.
#  Setting random BGM's.
#------------------------------------------------------------------------------
#  * Instructions:
#  To enable or disable the battle random BGM's used the following in a script
#  call:
#
#    disable_battle_random_bgm
#    enable_battle_random_bgm
#
#    (When disabled it will use the default battle BGM)
#
#
#  To add a BGM to play randomly when a battle starts use this in a script
#  call from an event:
#
#    add_random_battle_bgm(Name, Volume, Pitch)
#
#    Name   = BGM Filename (Just the name not the directory)
#    Volume = BGM Volume (0 to 100)  (Optional, default is 100)
#    Pitch  = BGM Pitch  (50 to 150) (Optional, default is 100)
#
#    Example:
#
#    add_random_battle_bgm("Battle3") or add_random_battle_bgm("Battle3", 80, 50)
#
#   
#  To remove a BGM from the list of random BGM to play when the battle starts,
#  use this in a script call from an event:
#
#    remove_random_battle_bgm(Name)
#
#    Name = BGM Filename (Just the name not the directory)
#
#    Example:  
#
#    remove_random_battle_bgm("Battle3")
#------------------------------------------------------------------------------
#  * Notes:
#  None.
#------------------------------------------------------------------------------
# WARNING:
#
# Do not release, distribute or change my work without my expressed written
# consent, doing so violates the terms of use of this work.
#
# If you really want to share my work please just post a link to the original
# site.
#
# * Not Knowing English or understanding these terms will not excuse you in any
#   way from the consequenses.
#==============================================================================
# * Import to Global Hash *
#==============================================================================
($imported ||= {})[:TDS_Battle_Random_BGM] = true

#==============================================================================
# ** TDS
#------------------------------------------------------------------------------
#  A module containing TDS data structures, mostly script settings.
#==============================================================================

module TDS
  #============================================================================
  # ** Battle_Random_BGM_Settings
  #----------------------------------------------------------------------------
  #  This Module contains battle random BGM settings.
  #============================================================================ 
  module Battle_Random_BGM_Settings
    #--------------------------------------------------------------------------
    # * Constants (Settings)
    #-------------------------------------------------------------------------- 
    # Initial list of random battle BGM's (Name, Volume, Pitch)
    Start_List = [
      RPG::BGM.new("Battle1"),
      RPG::BGM.new("Battle7", 100, 50),
      RPG::BGM.new("Battle8", 100, 150),
    ]
    # If true it will disable random battle BGM's when the game starts
    Disable_On_Start = false   
    # If true it will allow you to add duplicates to the random battle BGM list
    Allow_Duplicates = false
  end
end


#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system data. It saves the disable state of saving and
# menus. Instances of this class are referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :battle_random_bgm_disabled  # Battle Random BGM Flag
  attr_accessor :battle_random_bgm_list      # Battle Random BGM list
  #--------------------------------------------------------------------------
  # * Alias Listing
  #-------------------------------------------------------------------------- 
  alias tds_battle_random_bgm_game_system_initialize               initialize 
  alias tds_battle_random_bgm_game_system_battle_bgm               battle_bgm
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(*args, &block)
    tds_battle_random_bgm_game_system_initialize(*args, &block)
    init_battle_random_bgm
  end

  def init_battle_random_bgm
    # Set Battle Random BGM Flag
    @battle_random_bgm_disabled = TDS::Battle_Random_BGM_Settings::Disable_On_Start
    # Set Battle Random BGM List
    @battle_random_bgm_list = TDS::Battle_Random_BGM_Settings::Start_List.dup
  end
  #--------------------------------------------------------------------------
  # * Get Battle BGM
  #--------------------------------------------------------------------------
  def battle_bgm(*args, &block)
    # If Using Battle Random BGM
    return @battle_random_bgm_list.sample if use_battle_random_bgm?
    # Run Original Method
    tds_battle_random_bgm_game_system_battle_bgm(*args, &block)
  end 
  #--------------------------------------------------------------------------
  # * Determine if Battle Random BGM's should be used
  #--------------------------------------------------------------------------
  def use_battle_random_bgm? ; !@battle_random_bgm_disabled and !@battle_random_bgm_list.empty? end
  #--------------------------------------------------------------------------
  # * Enable or Disable Battle Random BGM
  #--------------------------------------------------------------------------
  def enable_battle_random_bgm  ; @battle_random_bgm_disabled = false end 
  def disable_battle_random_bgm ; @battle_random_bgm_disabled = true end
  #--------------------------------------------------------------------------
  # * Remove Random Battle BGM
  #     name : BGM name
  #--------------------------------------------------------------------------
  def remove_random_battle_bgm(name) ;  @battle_random_bgm_list.delete_if {|a| a.name == name} end   
  #--------------------------------------------------------------------------
  # * Add Random Battle BGM
  #     name : BGM name
  #--------------------------------------------------------------------------
  def add_random_battle_bgm(name, vol = 100, pitch = 100)
    # If Duplicates are not allowed in the random BGM list
    if !TDS::Battle_Random_BGM_Settings::Allow_Duplicates
      # Return if BGM name is already in list
      return if @battle_random_bgm_list.any? {|a| a.name == name}
    end
    # Add BGM to battle random BGM list
    @battle_random_bgm_list << RPG::BGM.new(name, vol, pitch)   
  end
end


#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
#  An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================

class Game_Interpreter
  #--------------------------------------------------------------------------
  # * Enable or Disable Battle Random BGM
  #--------------------------------------------------------------------------
  def enable_battle_random_bgm  ; $game_system.battle_random_bgm_disabled = false end 
  def disable_battle_random_bgm ; $game_system.battle_random_bgm_disabled = true end
  #--------------------------------------------------------------------------
  # * Remove Random Battle BGM
  #     name : BGM name
  #--------------------------------------------------------------------------
  def remove_random_battle_bgm(name) ; $game_system.remove_random_battle_bgm(name) end   
  #--------------------------------------------------------------------------
  # * Add Random Battle BGM
  #     name : BGM name
  #--------------------------------------------------------------------------
  def add_random_battle_bgm(name, vol = 100, pitch = 100) ; $game_system.add_random_battle_bgm(name, vol, pitch) end
end

The call you need for your old saved games is this:

Ruby:
$game_system.init_battle_random_bgm
"My fixed version" would be like this. Add this as a patch (below the script)
Ruby:
class Game_System
  def battle_random_bgm_disabled
    if @battle_random_bgm_disabled.nil?
      @battle_random_bgm_disabled = TDS::Battle_Random_BGM_Settings::Disable_On_Start
    end
    return @battle_random_bgm_disabled
  end

  def battle_random_bgm_list
    if @battle_random_bgm_list.nil?
      @battle_random_bgm_list = TDS::Battle_Random_BGM_Settings::Start_List.dup
    end
    return @battle_random_bgm_list
  end
 
  def use_battle_random_bgm? ; !battle_random_bgm_disabled and !battle_random_bgm_list.empty? end

  def remove_random_battle_bgm(name) ;  battle_random_bgm_list.delete_if {|a| a.name == name} end  

  def add_random_battle_bgm(name, vol = 100, pitch = 100)
    # If Duplicates are not allowed in the random BGM list
    if !TDS::Battle_Random_BGM_Settings::Allow_Duplicates
      # Return if BGM name is already in list
      return if battle_random_bgm_list.any? {|a| a.name == name}
    end
    # Add BGM to battle random BGM list
    battle_random_bgm_list << RPG::BGM.new(name, vol, pitch)   
  end

  def battle_bgm(*args, &block)
    # If Using Battle Random BGM
    return battle_random_bgm_list.sample if use_battle_random_bgm?
    # Run Original Method
    tds_battle_random_bgm_game_system_battle_bgm(*args, &block)
  end 

end
No need a script call.
My short version

Ruby:
class Game_System
  def battle_random_bgm_list
    @battle_random_bgm_list ||= []
  end
end
The short version that includes the starting list
Ruby:
class Game_System
  def battle_random_bgm_list
    @battle_random_bgm_list ||= TDS::Battle_Random_BGM_Settings::Start_List.dup
  end
end
Thanks Kyonides and TheoAllen for the quick fixes. Both work, though not sure what the short version is, couldnt get that to work. And ideally if it was perfect, would need neither a script call nor two seperate scripts if u wanna fix it further 🙂

Cuz ya script like this is awesome ot add to a super long game you've been playing 20+ hours and got bored of its BGM.. Seems like tons of games on rpgmaker.net also include lots of BGM, yet only use 1 file or theo nes only only once while you hear the default one for hours and hours of battles.

And Theo while I have your attention, i was also trying to get one of your scripts working from 10 years ago, difficulty script. As it's the only one I could find that lets you adjuts all the parameters individually so it looks awesome. It has the same issue, it only works on new games, crashes after a battle on existing savegames on line 173.

Here is the version im testing (think its the latest, hard to say these days, so many dead links for VXAce scripts, and i cant find it on your github:
If you're going to ask another different question, make another thread. I'll be there.

EDIT:
And ideally if it was perfect, would need neither a script call nor two seperate scripts if u wanna fix it further 🙂
I can agree about the script call, but there is nothing wrong with using two scripts.
Essentially, when you're using a script, you're modifying whatever is above it. In this case, TDS modified the behavior of the default script without directly modifying the default script to allow you to do random BGM, I fixed TDS's code without actually modifying the script itself.
okay new thread started here:

Original thread: https://forums.rpgmakerweb.com/threads/random-battle-music-bgm-without-starting-new-game.158249/