Cannot fetch variable

Been a long time since I've done line-by-line code, and I'm not familiar with Ruby syntax, etc., just yet.  I probably overlooked something simple (knowing my luck), but here's where things are.

Starting a new project, still only have the trial version of VX Ace.  Planning on having different battle BGM depending on who's the party leader (got that, no problem), but there are also some specific random encounters for which I wish to have some different BGM.  I figured I could have all such encounters first on the Troop listing, and then just make the desired BGM happen with an "if" function using a less-than sign.  The snag I've hit is trying to unbury the active Troop ID variable, so as to trigger the different BGM upon the start of battle transition (and not catch a few notes of something different before the desired tune kicks in).  I modified a script I found, the random battle BGM script by DiamondandPlatinum3, and here's where it stands (with a test value still in place):

#==============================================================================

# Battle BGM Handler, based of DiamondandPlatinum3's Random Battle Themes

#==============================================================================

module FightBGM

  module Themes

#==============================================================================

# Switch On to Choose Boss Tracks

#==============================================================================

  EVENT_SWITCH_ID = 2

#==============================================================================

# Select Themes; Remember the first slot is number zero.

#==============================================================================

  THEMES_ARRAY   = [

  [ "Special Random Encounter", 100, 100 ],

  [ "Battle - Fiona", 100, 100 ],

  [ "Battle - Rannah-Pozo", 100, 100 ],

  [ "Battle - Nahid", 100, 100 ],

  [ "Battle - Marcus", 100, 100 ],

  [ "Battle - Rashmika", 100, 100 ],

  [ "Battle - Quon", 100, 100 ],

  [ "Battle - Günter", 100, 100 ],

  [ "Battle - Racquel", 100, 100 ],

]

  end

end

#==============================================================================

# ** BattleManager

#==============================================================================

module BattleManager

  #--------------------------------------------------------------------------

  # * Overwritten Method: Play Battle BGM

  #--------------------------------------------------------------------------

  def self.play_battle_bgm

    if $game_troop.id < 2  <<--- THIS is where I'm running into trouble.

      leader = 0

    else

      leader = $game_party.members[0].id

    end

    unless $game_switches[FightBGM::Themes::EVENT_SWITCH_ID]

      RPG::BGM.new(*FightBGM::Themes::THEMES_ARRAY[leader]).play

    else

      $game_system.battle_bgm.play

    end

    RPG::BGS.stop

  end

end

So...how do I fetch this variable?  Thanks for the help.
Try $game_troop.troop.id


You can also use $game_party.leader.id instead of $game_party.members[0].leader - they'll give you the same thing.
Cool.  Thanks.  It's working smooth now.
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/cannot-fetch-variable.19692/