• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Which Pokémon Masters protagonist do you like most? Let us know by casting a vote in our Masters favorite protagonist poll here!
  • Red, Hilda, Paxton, or Kellyn - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Music changes according to time of day?

Minokun

The Rival in Space
  • 107
    Posts
    11
    Years
    • Seen Sep 18, 2019
    I noticed that in the Game the music changes in some maps from when it was night and then changed it back when it was day. I looked on the wiki but the article I was looking for didn't exist (Literally), and I don't think any NPC explains this in the Game either. Any help?
    (Btw, if there is another article or NPC that Does explain this and I'm an idiot please just tell me.)
     
    Hello!

    Have you tried looking at which map does this and what songs they play? Have you also tried looking at your Materialbase and did you notice two identical audio files called "021-Field04" and "021-Field04n"?

    You said you noticed a map that had a changing background. If you go to that map's properties, you'll notice it will read that it is using one of the BGM files I'm referring to. This is the "regular BGM". When any BGM has "n" at the end of its filename contained in the BGM folder, that song will be played when night occurs and will revert during the day. If "021-Field04n" does not exist, then no night BGM will play.

    If you wish to know why that is, look at this. This snippet is contained in Game_Map_

    No worries! It's not exactly explained in the Wiki but at least it is possible!
    Hope this helps!

    Code:
     #-----------------------------------------------------------------------------
      # * Autoplays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplayAsCue
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
          else
            pbCueBGM(@map.bgm,1.0)
          end
        end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end
     
    Last edited:
    Hello!

    Have you tried looking at which map does this and what songs they play? Have you also tried looking at your Materialbase and did you notice two identical audio files called "021-Field04" and "021-Field04n"?

    You said you noticed a map that had a changing background. If you go to that map's properties, you'll notice it will read that it is using one of the BGM files I'm referring to. This is the "regular BGM". When any BGM has "n" at the end of its filename contained in the BGM folder, that song will be played when night occurs and will revert during the day. If "021-Field04n" does not exist, then no night BGM will play.

    If you wish to know why that is, look at this. This snippet is contained in Game_Map_

    No worries! It's not exactly explained in the Wiki but at least it is possible!
    Hope this helps!

    Code:
     #-----------------------------------------------------------------------------
      # * Autoplays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplayAsCue
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
          else
            pbCueBGM(@map.bgm,1.0)
          end
        end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end

    DUUUUUUUUUUUUUUUUUUH! Thanks, I'm such an idiot.
     
    I want to add conditions for morning and afternoon.
    How would I do this without incurring a Syntax Error in Game_Map?
     
    I was actually just about to ask about this as well. Although, I would rather not go through the hassle of having two of every piece of music cluttering up my audio folder.


    Is there a way where I could just adjust the pitch of my existing music based on the time of day? I was planning on playing my music at a normal pitch during the day, and a lower pitch at night. I already tried doing this through events, and while it works somewhat, it lags the game a ton when I try adding more and more events for each town and route. Is there another way to do this through scripting?
     
    Last edited:
    I want to add conditions for morning and afternoon.
    How would I do this without incurring a Syntax Error in Game_Map?

    Code:
    isNight?

    I'm sure you can figure how to make it check if its morning lol
     
    Code:
    isNight?

    I'm sure you can figure how to make it check if its morning lol

    I know, but the problem is not that simple.
    I found the checks for morning and afternoon and attempted:
    Code:
      def autoplayAsCue
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
          else
        if PBDayNight.isMorning?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
            pbCueBGM(@map.bgm.name+"m",1.0,@map.bgm.volume,@map.bgm.pitch)
          else
            pbCueBGM(@map.bgm,1.0)
          end
        end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end

    I got a Syntax Error on Line 480 where the Class Game_Map is defined.
    also tried else if statement. same result
    I'm a bit rusty, but I can't find out why this doesn't work.
     
    ^Try including 'pbCueBGM(@map.bgm,1.0)' after both music cues (at the moment it's only after the second 'morning' conditional). Otherwise, or, in addition to this, try changing that second 'if' to 'elsif'.
     
    ^Try including 'pbCueBGM(@map.bgm,1.0)' after both music cues (at the moment it's only after the second 'morning' conditional). Otherwise, or, in addition to this, try changing that second 'if' to 'elsif'.

    I tried this and got a similar error.
    why do you think this is?
     
    Alright,
    After a long series of trial and error, I managed to develop a far more expanded and specific code that will allow for Morning and Afternoon conditions to be checked.
    Every other method I used resulted in a Syntax Error, but this one should be totally safe for all versions of Essentials.

    Simply replace the "def autoplayAsCue" and "def autoplay" sections in Game_Map with the following code:
    Code:
      #-----------------------------------------------------------------------------
      # * Autoplays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplayAsCue
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
          end
          if PBDayNight.isAfternoon?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
            pbCueBGM(@map.bgm.name+"a",1.0,@map.bgm.volume,@map.bgm.pitch)
          end
          if PBDayNight.isMorning?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
            pbCueBGM(@map.bgm.name+"m",1.0,@map.bgm.volume,@map.bgm.pitch)
          end
          
          if PBDayNight.isNight?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm,1.0)
          end
          if PBDayNight.isAfternoon?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
            pbCueBGM(@map.bgm,1.0)
          end
          if PBDayNight.isMorning?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
            pbCueBGM(@map.bgm,1.0)
          end
          if PBDayNight.isDay?(pbGetTimeNow) &&
                !PBDayNight.isMorning?(pbGetTimeNow) &&
                !PBDayNight.isAfternoon?(pbGetTimeNow)
            pbCueBGM(@map.bgm,1.0)
          end
          end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end
      #-----------------------------------------------------------------------------
      # * Plays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplay
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
                pbBGMPlay(@map.bgm.name+"n",@map.bgm.volume,@map.bgm.pitch)
          end
          if PBDayNight.isMorning?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
                pbBGMPlay(@map.bgm.name+"m",@map.bgm.volume,@map.bgm.pitch)
          end
          if PBDayNight.isAfternoon?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
                pbBGMPlay(@map.bgm.name+"a",@map.bgm.volume,@map.bgm.pitch)
          end
              
          if PBDayNight.isAfternoon?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
            pbBGMPlay(@map.bgm)
          end
          if PBDayNight.isMorning?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
            pbBGMPlay(@map.bgm)
          end
          if PBDayNight.isNight?(pbGetTimeNow) &&
                !FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbBGMPlay(@map.bgm)
          end
          if PBDayNight.isDay?(pbGetTimeNow) &&
                !PBDayNight.isMorning?(pbGetTimeNow) &&
                !PBDayNight.isAfternoon?(pbGetTimeNow)
            pbBGMPlay(@map.bgm)
          end
          end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end
    Simply add "a" or "m" to the end of your audio filename for Afternoon and Morning respectively, as with "n" for Night.


    Happy Coding!
     
    Alright,
    After a long series of trial and error, I managed to develop a far more expanded and specific code that will allow for Morning and Afternoon conditions to be checked.
    Every other method I used resulted in a Syntax Error, but this one should be totally safe for all versions of Essentials.

    Simply replace the "def autoplayAsCue" and "def autoplay" sections in Game_Map with the following code:
    Code:
      #-----------------------------------------------------------------------------
      # * Autoplays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplayAsCue
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
            pbCueBGM(@map.bgm.name+"n",1.0,@map.bgm.volume,@map.bgm.pitch)
          elsif PBDayNight.isAfternoon?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
            pbCueBGM(@map.bgm.name+"a",1.0,@map.bgm.volume,@map.bgm.pitch)
          elsif PBDayNight.isMorning?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
            pbCueBGM(@map.bgm.name+"m",1.0,@map.bgm.volume,@map.bgm.pitch)
          else
            pbCueBGM(@map.bgm,1.0)
          end
        end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end
      #-----------------------------------------------------------------------------
      # * Plays background music
      #   Plays music called "[normal BGM]n" if it's night time and it exists
      #-----------------------------------------------------------------------------
      def autoplay
        if @map.autoplay_bgm
          if PBDayNight.isNight?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "n")
                pbBGMPlay(@map.bgm.name+"n",@map.bgm.volume,@map.bgm.pitch)
          elsif PBDayNight.isMorning?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "m")
                pbBGMPlay(@map.bgm.name+"m",@map.bgm.volume,@map.bgm.pitch)
          elsif PBDayNight.isAfternoon?(pbGetTimeNow) &&
                FileTest.audio_exist?("Audio/BGM/"+ @map.bgm.name+ "a")
                pbBGMPlay(@map.bgm.name+"a",@map.bgm.volume,@map.bgm.pitch)
          else
            pbBGMPlay(@map.bgm)
          end
        end
        if @map.autoplay_bgs
          pbBGSPlay(@map.bgs)
        end
      end
    Simply add "a" or "m" to the end of your audio filename for Afternoon and Morning respectively, as with "n" for Night.


    Happy Coding!

    I replaced the long series of "if/end"s with one "if/elsif/elsif/.../else/end" string. This may have been one of the methods you tried that threw up a syntax error.

    @Minokun - PokeCommunity breaks code. Be sure to click "show printable version" before copying either my or Khari's code.
     
    I replaced the long series of "if/end"s with one "if/elsif/elsif/.../else/end" string. This may have been one of the methods you tried that threw up a syntax error.

    @Minokun - PokeCommunity breaks code. Be sure to click "show printable version" before copying either my or Khari's code.

    AND THERE WAS THE PROBLEM!

    I had made the mistake of entering "else if" instead of "elsif", which works entirely different in Ruby than many other languages.
    Thank you kind sir and good work!
     
    AND THERE WAS THE PROBLEM!

    I had made the mistake of entering "else if" instead of "elsif", which works entirely different in Ruby than many other languages.
    Thank you kind sir and good work!

    You're welcome.

    Don't worry, I came from a coding language where "elseif" was spelled with another E, so it took me a while to catch on as well.
     
    Back
    Top