udime123

Director of Fate
Veteran
Joined
Mar 29, 2018
Messages
104
Reaction score
15
First Language
English
Primarily Uses
RMMV
Hello, everyone!
So, I've employed Hime's Menu Music plugin, and it works largely as intended aside from an oversight that it would appear is an issue with the plugin itself: when the game is saved through the menu (but not through other means such as events), the music that plays after loading is the menu music rather than the music intended for that map that the game was saved in.

After doing a bit of digging and troubleshooting, I managed to find the reason for this, but I'm not sure how to actually fix it due to my inexperience with Javascript which is why I've come here for your help!

So, the main source of the issue is this script right here in rpg_objects.js:
1590711404455.png

Basically, what this script does is tell the game to remember what song is playing right before saving, and after a save file is loaded, play that song again.
The issue is that due to the nature of the Menu Music plugin, the song that is currently saving while in the menu is always going to be the menu music, unless you have the music disabled which would defeat the purpose.

An important thing to note is that the Menu Music plugin does have some code that saves the music played before opening the menu, which plays the music as intended once you return to the field.
1590711705965.png

So, I tried fiddling around with the code a bit in both rpg_objects.js (which I'll be nicknaming 'Objects' for the rest of this thread) as well as HIME_MenuMusic.js (nicknaming 'MM'), with little success. First, I tried to simply remove the part in Objects that tells the game to save the current BGM, hoping it would cause the onAfterLoad script to instead load the most recent saved BGM (our field music thanks to MM). This simply pulled a name undefined error, presumably since onAfterLoad was trying to pull this._bgmOnSave as opposed to MM's this._mapBgm.

So, my next attempt was to edit Objects to try to load this._mapBgm instead of this._bgmOnSave, but this yielded no results as well (I assumed that's because the two scripts are in different files, but with my lack of JS understanding I honestly can't say for certain).

With that not working, I thought that perhaps if I removed the entire script for saving and loading the BGM, the game would simply autoplay whatever it was supposed to for that map. Of course, it ended up just playing no music instead.

After that failed, my next attempt was to make onAfterLoad simply follow the same script that Menu Music does if you've turned the Replay code back on:
Code:
$gameMap.autoplay();

I had assumed this code would simply tell the game to play whatever music the map is assigned for Autoplay, but this pulled a Name Undefined error anyways.

Finally, my last resort was to try to pull those edits to Objects into MM instead, but after a variety of different alterations, I ultimately decided I'm probably not going to be able to figure this out through brute force like I usually do.

So, I was wondering if anyone knew how to get the game to play the map's intended music on load instead of the music playing on the menu before saving. I think our key to this is going to be MM's this._mapBgm, but I'm open to just about any ideas you guys might have on how to approach this!


Thank you!
 

Attachments

  • 1590712098397.png
    1590712098397.png
    1.4 KB · Views: 2

Zioxboy

Villager
Member
Joined
Aug 18, 2020
Messages
9
Reaction score
2
First Language
Spanish
Primarily Uses
RMMV
Bump, same issue here with my game.
Did you manage to fix it?
 

Traverse

Veteran
Veteran
Joined
Jul 3, 2014
Messages
192
Reaction score
125
First Language
English
Primarily Uses
I can't speak for the guy and I have no idea whether he came up with anything - but I can at least respect he tried. I'd say he came close in his attempts, except he both sorta did and didn't.

He was on the right track in recognizing that the plugin stores the map BGM in a variable and that during save file creation, it was instead storing the currently-playing BGM when it needed to store the map BGM instead. But he was on the wrong track in trying to get the game to load the "remembered" map BGM from the plugin, because the plugin doesn't actually remember it once the game is closed (that's what save files are for). Variables get wiped once the game gets closed, that's why you need to reload them from persistent save files.
So, my next attempt was to edit Objects to try to load this._mapBgm instead of this._bgmOnSave, but this yielded no results as well (I assumed that's because the two scripts are in different files, but with my lack of JS understanding I honestly can't say for certain).
This didn't work, not just because they come from different files/objects but because "_mapBgm" simply doesn't get saved into the save file anyway. There is no variable called "_mapBgm" in a save file to read (and even if he tried to read it from the plugin, the _mapBgm variable in the plugin would be blank when the game is launched).

The variable "_bgmOnSave" is what gets saved into the save file and the contents of that variable are meant to be the currently playing BGM at time of saving: "AudioManager.saveBgm()", which fetches the currently playing BGM (which would be Hime's menu music).

The solution is actually to swap out the contents stored into "_bgmOnSave", so that instead of it storing the currently playing BGM, it instead stores the one that Hime's plugin keeps in its "_mapBgm".

You can either directly edit the "Game_System.prototype.onBeforeSave" function in rpg_objects.js to do this. Or else edit Hime's plugin and put in the alteration like so:
JavaScript:
  var TH_MenuMusic_GameSystem_onBeforeSave = Game_System.prototype.onBeforeSave;
  // Stores the original "onBeforeSave" function before modifying it, in order to
  // avoid clashes with other plugins that may have also modified the function.
  Game_System.prototype.onBeforeSave = function() {
  // Modifies (overwrites) the onBeforeSave function.
    TH_MenuMusic_GameSystem_onBeforeSave.call(this);
    // Executes the previously stored "onBeforeSave" function to do everything it did before.
    this._bgmOnSave = TH.MenuMusic._mapBgm;
    // Overwrites the contents of the _bgmOnSave variable.
    this._bgsOnSave = TH.MenuMusic._mapBgs;
    // Overwrites the contents of the _bgmOnSave variable.
  };
 
Last edited:

udime123

Director of Fate
Veteran
Joined
Mar 29, 2018
Messages
104
Reaction score
15
First Language
English
Primarily Uses
RMMV
I can't speak for the guy and I have no idea whether he came up with anything - but I can at least respect he tried. I'd say he came close in his attempts, except he both sorta did and didn't.

He was on the right track in recognizing that the plugin stores the map BGM in a variable and that during save file creation, it was instead storing the currently-playing BGM when it needed to store the map BGM instead. But he was on the wrong track in trying to get the game to load the "remembered" map BGM from the plugin, because the plugin doesn't actually remember it once the game is closed (that's what save files are for). Variables get wiped once the game gets closed, that's why you need to reload them from persistent save files.

This didn't work, not just because they come from different files/objects but because "_mapBgm" simply doesn't get saved into the save file anyway. There is no variable called "_mapBgm" in a save file to read (and even if he tried to read it from the plugin, the _mapBgm variable in the plugin would be blank when the game is launched).

The variable "_bgmOnSave" is what gets saved into the save file and the contents of that variable are meant to be the currently playing BGM at time of saving: "AudioManager.saveBgm()", which fetches the currently playing BGM (which would be Hime's menu music).

The solution is actually to swap out the contents stored into "_bgmOnSave", so that instead of it storing the currently playing BGM, it instead stores the one that Hime's plugin keeps in its "_mapBgm".

You can either directly edit the "Game_System.prototype.onBeforeSave" function in rpg_objects.js to do this. Or else edit Hime's plugin and put in the alteration like so:
JavaScript:
  var TH_MenuMusic_GameSystem_onBeforeSave = Game_System.prototype.onBeforeSave
  // Stores the original "onBeforeSave" function before modifying it, in order to
  // avoid clashes with other plugins that may have also modified the function.
  Game_System.prototype.onBeforeSave = function() {
  // Modifies (overwrites) the onBeforeSave function.
    TH_MenuMusic_GameSystem_onBeforeSave.call;
    // Executes the previously stored "onBeforeSave" function to do everything it did before.
    this._bgmOnSave = TH.MenuMusic._mapBgm;
    // Overwrites the contents of the _bgmOnSave variable.
    this._bgsOnSave = TH.MenuMusic._mapBgs;
    // Overwrites the contents of the _bgmOnSave variable.
  };
I had given up on this long ago (the compromise we came up with was to simply make a "quick save" button that opens the save screen on the map, thus skipping the menu music entirely), but this honestly gives me a ton of closure after ripping my hair out over it for a couple of days. Thank you very much.
 

Zioxboy

Villager
Member
Joined
Aug 18, 2020
Messages
9
Reaction score
2
First Language
Spanish
Primarily Uses
RMMV
Holy Moly you are amazing dude, thank you for this. This may be the only solution on the entire Internet. Tried another Menu Music plugin but same issue. Finally solved.
 

Latest Threads

Latest Posts

Latest Profile Posts

Moving day is on May 12! A month from today! I'm finally getting my own apartment!
I made the logo and title screen for my game (Still rough but at least it's got a design now)
Eyy1s2gXIAMzfFN
Eyy1s2hXMAEmiRA
BCj
Whelp, it's been a while. Had another retina surgery on april 1st on my left eye. Well, 4 time's the charm, right? *recovery mode on*
The next JABS update will include ally AI and an aggro system.

Question:
What would YOU expect to happen if you had four+ party members in an ABS, all fighting either together or separately or a mix of the two, and the player hits "swap leader" button?
It currently pulls all followers to the player's location, removes all aggro towards enemies, and swaps them.
Time to wear a new face again...

Should keep things interesting huh? @EpicFILE :p

Forum statistics

Threads
110,335
Messages
1,052,448
Members
143,379
Latest member
sainti
Top