Help, can I Save the name of currentBgm on a variable?

Status
Not open for further replies.

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
209
Reaction score
36
First Language
English Spanish
Primarily Uses
I was wondering if I can save the name of the currentBgm playing on a variable?

Thanks!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,823
Reaction score
12,231
First Language
English
Primarily Uses
RMMV
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.
 

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
209
Reaction score
36
First Language
English Spanish
Primarily Uses
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
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,823
Reaction score
12,231
First Language
English
Primarily Uses
RMMV
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?
 

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
209
Reaction score
36
First Language
English Spanish
Primarily Uses
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?)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,823
Reaction score
12,231
First Language
English
Primarily Uses
RMMV
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?
 

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
209
Reaction score
36
First Language
English Spanish
Primarily Uses
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.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,823
Reaction score
12,231
First Language
English
Primarily Uses
RMMV
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.
 

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
209
Reaction score
36
First Language
English Spanish
Primarily Uses
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.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,823
Reaction score
12,231
First Language
English
Primarily Uses
RMMV
A screenshot might help, maybe?

Is the BGM playing on the map, or in a battle?
 

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
209
Reaction score
36
First Language
English Spanish
Primarily Uses
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.
 

Attachments

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,823
Reaction score
12,231
First Language
English
Primarily Uses
RMMV
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?
 

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
209
Reaction score
36
First Language
English Spanish
Primarily Uses
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?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,823
Reaction score
12,231
First Language
English
Primarily Uses
RMMV
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.
 

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
209
Reaction score
36
First Language
English Spanish
Primarily Uses
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 the
Code:
 this.replayBgmAndBgs();
In a better spot.

Let me play a bit with that line and let you know.

Thanks for all the time you spent on this.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,823
Reaction score
12,231
First Language
English
Primarily Uses
RMMV
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 :)
 

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
209
Reaction score
36
First Language
English Spanish
Primarily Uses
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.
 

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
209
Reaction score
36
First Language
English Spanish
Primarily Uses
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!
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
21,791
Reaction score
11,006
First Language
English
Primarily Uses
RMVXA
[closed]IgnoreMe[/closed]
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

My plan after learning to make my voice girly "Wow! You sounds cute!" "But actually I'm a man!" "Nooooo!!!" hehehe...
I get haunted from bugs that emit a terrible stench after being killed.
At first, I was going to put player objectives on the screen labeling it as "Helpful voices"... But that's dumb, I have a madness system. It will simply whisper objectives.... I mean they're probably objectives. The voices wouldn't lie right? They're friendly, and ...helpful. So clearly you should do what they say. Just watch the dark corners of your screen for advice and it will all work out! :LZSexcite:
Take care of your immune system: Go to sleep. If you looked at the clock an hour ago or four and it was way late then maybe now is the time. Mmm sleep...

Forum statistics

Threads
95,667
Messages
930,913
Members
126,005
Latest member
Rbennin
Top