I was wondering if I can save the name of the currentBgm playing on a variable?
Thanks!
Help, can I Save the name of currentBgm on a variable?
● ARCHIVED · READ-ONLY
-
-
The BGM is actually a BGM object - it has a name, volume, pitch, pan and position.
You can use AudioManager._currentBgm.name in the Script part of a Control Variables command to save the name of the currently-playing BGM, but you would not be able to use it to replay it at a later stage. -
Hi again! You should start charging a fee =P
Ok, before I posted this, I tried to save the name of the bgm currently playing like this:
myBgm = AudioManager._currentBgm.name, but it showed me an error.
Im making a little system (eventing) to handle bgms, like change the volume or pan or pitch of the same bgm, so instead of placing the name myself into the variable(Since im having at least 10 bgms) its just easier to have the name on the variable.
Can it be done?
Thanks -
What was the error it showed you? Did you actually have a BGM playing at the time? If you didn't, it might say something like 'undefined function name for AudioManager._currentBgm'
When you say "on a variable", do you mean a variable that you access through the Control Variables command, or a variable that you create via script?
So you just want to change a property on the BGM that's currently playing, not to change the BGM itself (play a different BGM entirely)? Should be pretty easy, but I need to understand how you're approaching it. Perhaps you can show a screenshot of what you've got so far? -
Yes, I just want to modify the current Bgm playing, not play new one.
And yeah, there is a BGM playing at the moment of my call, tried both, a variable from the Control Variables and one created by me, both with the same error:
TypeError: Cannot read property 'name' of null. (Is it because is not a BGM on the map properties AutoplayBgm but instead a Bgm played by an event command?) -
no, if there's a bgm playing it should pick it up. How are you playing it, if not via map properties - Play BGM command? Do you have any plugins related to audio?
-
Yes, with the play BGM event command. The only plug in that is related to audio is Yanfly Bgm control, but its turned off and DreamX Change sound, chich only modifes some SE of the data base but no BGMs.
-
It works for me:
Code:Play BGM: Town1 Control Variables [0001: Stuff] = Script: AudioManager._currentBgm.name Text: \v[1]
shows Town1 in a text dialog.
Can you please show me a screenshot? I'm thinking there's a typo in there. Note - _currentBgm is not the same as _currentBGM - make sure you're using the correct case. -
Hmm. Ok, the problem is WHENI am calling. Im using a SRD plug in, an event that runs before every fight. I was running the script in that common event and will not work, I just did it on an event on the map, and yeah, it grabs the name. So I guess I cant run in on that common event, then.
-
A screenshot might help, maybe?
Is the BGM playing on the map, or in a battle? -
The BGM I want to save is the one playing on the map, just before the battle start.
I attached both images, the one where i call the command and the console´s error.
EDIT: Dont forget that this is a common event automatically called by a plug in every single battle, before it starts. -
Do you have links to the plugins?
A part of setting up battle is to stop the map BGM and start the battle BGM. It's possible whatever plugin is calling the battle does it at a time when the map BGM has been turned off.
How is this system of yours working? If it's via events, why are you putting the script into a common event that's called just prior to battles? What does the system have to do with battles if you're eventing it on the map? -
Yes, my thought exactly. That maybe im calling the script just when the information is no longer there and before the battle bgm starts.
Im implementing this system because, when you win/escape the fight, the map bgm starts playing when the aftermath is shown. I didnt like it, I prefer the bgm starts to play when you actually are back on the map. So If I turn the bgm volume it cannot be heard on the aftermath and when the player is on the map again, I turn the volume on and it will "resume". If I turn the bgm off before the fight and on after, it will start form the beginning and it will not feel smooth.
Thats why I wanted to do all this. Makes sense? or you can think another way to accomplish this that Im missing? -
You could just make a plugin request to not start playing the map BGM until you're actually back on the map :)
put this into a file with a .js extension in your plugins folder, and add it as a plugin.
Code:BattleManager.processVictory = function() { $gameParty.removeBattleStates(); $gameParty.performVictory(); this.playVictoryMe(); this.makeRewards(); this.displayVictoryMessage(); this.displayRewards(); this.gainRewards(); this.replayBgmAndBgs(); this.endBattle(0); };
I haven't tested it, but the timing should be a lot better. -
Thanks!
Now, Im using Mogs Battle results. So if I place your code before Battle Result, well of course it gets overwritten. And if I place it after, Mogs Battle resutl doesnt play AND the Bgm still resumes in the aftermath, not until map.
But I see what are we trying, to get theCode:In a better spot.this.replayBgmAndBgs();
Let me play a bit with that line and let you know.
Thanks for all the time you spent on this. -
I just noticed you said this also happens when you escape battle. I couldn't really see much that happens when you escape that would delay return to the map, so you might have to look for additional locations.
Alternately, you could try a Save BGM, Stop BGM and Restore/Resume BGM command combo on the event that calls the battle (save/stop before the battle, restore/resume after), if your battles are being called from events.
I won't ask for a link to Mog's script, as I know it's one big massive project file containing every script he's ever written, and I don't want to look through that.
Good luck :) -
Haha yeah, I wouldnt put you through it. My battles are not called from events, are random encounter, fortunately I have another plug in that runs just for random encounters...so the call there might do the trick.
Thanks, Ill let you know how I fixed it. -
Aaaaand it worked with the plug in that runs before random encounters (HIME´s). So for random encounter I will use call on said plug in and for evented encounters well, there is no problem there.
Solved. Thanks! -
[closed]IgnoreMe[/closed]