BGM and Map BGM replay problem

● ARCHIVED · READ-ONLY
Started by Milena 13 posts View original ↗
  1. I am replicating Battle Processing through a code like this:

    def call_battle_screen $game_system.battle_bgm = $game_temp.newbgm BattleManager.setup($game_temp.battle_enemy, true, true) BattleManager.event_proc = Proc.new {|n| @branch[@indent] = n } $game_player.make_encounter_count SceneManager.call(Scene_Battle) endwhere $game_temp.newbgm is an attribute accessor where newbgm = Battle2.

    But whenever I call that on the scene I made, it never calls the new BGM (it means that my Scene_Battle) just plays silent. It doesn't have a BGM, whereas I wanted it to play Battle2.

    The Scene_Battle works fine, but whenever I escape or win, an error saying replay method is unidenfitied for nil NilClass. It is rooted down under the BattleManager's

    #-------------------------------------------------------------------------- # * Resume BGM and BGS #-------------------------------------------------------------------------- def self.replay_bgm_and_bgs @map_bgm.replay unless $BTEST @map_bgs.replay unless $BTEST endmethod. 

    What am I missing here?
  2. did you have screenshoot of your error?
  3. nio kasgami said:
    did you have screenshoot of your error?
    7j2fquu.jpg

    it is basically as I stated above, that replay becomes not identified as I called that out.

    As for the BGM, I suppose a screenshot can't be done, since calling the method would just give me a silent battle.
  4. of what I see of this...you are not correctly call the replay class method

    also why did you use ''global'' for this? (the @) this is a weird way for calling a Instance...
  5. That is the default for BattleManager. 
  6. Milena said:
    That is the default for BattleManager. 
    ho!  this is obvious i am tired D: 

    well naturally when this call this kind of Error repport is more about you don't called correctly your instance but this surprise me...this is the default way for calling the replay I wounder why this do that...

    and you also said this mute song...

    naturally I assume because the method is not called correctly the song will not play...but not sure I need to check more deeply what you do ..
  7. I'll explain about the error :
    The thing is, @map_bgm is a nil value, so replay method will yelling at you. Now that is @map_bgm and why in your case the value is nil? (Because by default it should not nil)

    Let's look here:

    If you hovering up a little you found this, this is the method that assign the value for @map_bgm and @map_bgs

      #--------------------------------------------------------------------------  # * Save BGM and BGS  #--------------------------------------------------------------------------  def self.save_bgm_and_bgs # This method used to store the map BGM and BGS if any, so it can be played again after the battle end.    @map_bgm = RPG::BGM.last    @map_bgs = RPG::BGS.last  endAnd here is the default method used by the system before executing a battle process
    This method is in Scene_Battle

    #--------------------------------------------------------------------------  # * Preprocessing for Battle Screen Transition  #--------------------------------------------------------------------------  def pre_battle_scene    Graphics.update    Graphics.freeze    @spriteset.dispose_characters    BattleManager.save_bgm_and_bgs # <= This is the where that @map_bgm is get it's value    BattleManager.play_battle_bgm    Sound.play_battle_start  endNow the problem is in your custom method

    def call_battle_screen $game_system.battle_bgm = $game_temp.newbgm BattleManager.setup($game_temp.battle_enemy, true, true) BattleManager.event_proc = Proc.new {|n| @branch[@indent] = n } $game_player.make_encounter_count SceneManager.call(Scene_Battle) endSee what the problem already? Yes your method didn't have this BattleManager.save_bgm_and_bgs, so when the battle is over, either by win or escape, when the system is calling this :

    Spoiler
    The game will crash because the @map_bgm is nil
    def self.process_victory # This if win play_battle_end_me replay_bgm_and_bgs #<= Here one $game_message.add(sprintf(Vocab::Victory, $game_party.name)) display_exp gain_gold gain_drop_items gain_exp SceneManager.return battle_end(0) return true end
    Code:
    #--------------------------------------------------------------------------  # * Abort Processing  #--------------------------------------------------------------------------  def self.process_abort # this for escaping    replay_bgm_and_bgs # <= here's another    SceneManager.return    battle_end(1)    return true  end
    Code:
       def self.process_defeat # and this if you defeated but can lose    $game_message.add(sprintf(Vocab::Defeat, $game_party.name))    wait_for_message    if @can_lose      revive_battle_members      replay_bgm_and_bgs  # <= here's another      SceneManager.return    else      SceneManager.goto(Scene_Gameover)    end    battle_end(2)    return true  end
    And for your BGM that won't be playing actually there's an easier way to play it
    Just use this RPG::BGM.new("filename", 100, 100).play
    Now you can just replace the argument with a variable , for ex : MY_BGM = ["Battle2", 100, 100]
    Then it becomes like this RPG::BGM.new(*MY_BGM).play
    So your custom method become like this :
     

    def call_battle_screen # $game_system.battle_bgm = $game_temp.newbgm Don't use this # oh yeah you should call this too BattleManager.save_bgm_and_bgs # <= this thing RPG::BGM.new(*MY_BGM).play # <= use this instead. BattleManager.setup($game_temp.battle_enemy, true, true) BattleManager.event_proc = Proc.new {|n| @branch[@indent] = n } $game_player.make_encounter_count SceneManager.call(Scene_Battle) endTry it I'm pretty sure the BGM will play. :)

    P.S : Okay I've made so many typo, wew..
  8. The BGM does play that way, however, when you still escape or win, replay error still ensues. The problem I have right now is how to emulate the real battle process with saving the bgm and bgs, so that error won't return, while not being able to edit a whole lot of those in BattleManager. :\
  9. This thing : BattleManager.save_bgm_and_bgs
    have you already add this line in your method call_battle_screen ?

     
  10. Yes, it returns an array error.
  11. I have tried your method in my test game, I define it in Game_Interpreter and call it from scipt commad, it did not throw me an error after I win or escape, and the strange thing is why it gives an array error? Can you show the error message? Probably you assign the battlebgm with an array and not with RPG::BGM object.

     Try this method, this should not throw any error, I have test this:
     

    class Game_Interpreter def call_battle_screen $game_system.battle_bgm = RPG::BGM.new("Battle2", 100, 100) # <= you store this RPG::BGM object in $game_temp.battlebgm BattleManager.save_bgm_and_bgs BattleManager.setup(3, true, true) BattleManager.event_proc = Proc.new {|n| @branch[@indent] = n } $game_player.make_encounter_count SceneManager.call(Scene_Battle) end end # End of Game_InterpreterI don't know if that is waht you want, but I hope it is.. :)
  12. This works surprisingly well for Game_Interpreter, but seeing I have made all these process into a Scene, it won't work. Somehow the replay error is still there :|
  13. Geez.. That's the problem, you call this method in a scene that is not Scene_Map :headshake: .
    If you look at this method

    #--------------------------------------------------------------------------  # * Resume BGM and BGS  #--------------------------------------------------------------------------  def self.replay_bgm_and_bgs    @map_bgm.replay unless $BTEST # There's a reason why @map_bg.replay UNLESS $BTEST    @map_bgs.replay unless $BTEST  endSo basically the @map_bgm will become nil if the current scene after the battle scene is not Scene_Map, you can alias that BattleManger replay bgm and bgs method so it only replays if the scene is Scene_Map. Okay, to be honest I don't really know the flow, but that is the truth. Unless the scene after the battle is Scene_Map, then @map_bgm will be nil and throw you an error if replay called.

    I believe there are a way to do this(replay bgm in the current scene after a battle from that scene, but I haven't do any research about this, sorry :| )

    EDIT : I just notice this line in your battle setup
       BattleManager.event_proc = Proc.new {|n| @branch[@indent] = n }  
    I bet you got this code from Game_Interpreter? Sorry If not, but now I figure out why it throws you and array error. Like this maybe []= for nil:NilClass
    That's happened because @indent is an instance variable from Game_Interpreter class(I believe it's used for command event purpose) that's why it's nil in your case, thus throws an error at you, but not when you call your method via Game_Interpreter script call. Try to remove that line and it won't crash your game again.