Fangames > Programming Questions

Music volume

(1/1)

Ataosama:
Hello, when I want to lower the volume of a music I use this code : sound_volume(music, number).

The problem is that when I restart, the volume doesn't go back to 1 (100%), so how could I do that ? (I use the yuuutu engine, if that matters)

Derf:
You have to use a global variable instead that is saved and loaded in the save and load scripts.

Looking in the respective scripts for how they handle said variables and it should be as easy as copy and pasting over the code and adjusting it slightly. Remember to initialise the variable at the start of the game at the default volume before the game loads the variables though.

Incidentally I used Yuuutu for a previous project and it is by far my least favourite engine, pointless bloated and over-complicated. Most of my time was spent rewriting the saving/music systems etc.

Ataosama:
I started to program something like 2/3 weeks ago so sorry if I didn't understand what you mean but isn't that suppose to save the volume ?

My problem is that I don't know how to put the volume back at 100% when I press R/F2.

 I guess I could put "sound_volume(music, 1)" in the press R/F2 event for literally all my musics but there is probably a better way to do that.

Then sorry if what you said would solve my problem, like I said I'm new in programming :p

Derf:
It's fine, everyone starts somewhere :~)

Here's what I would do:

I would initialise a variable in the script called "SetGlobalOption" called "global.vol" and set it to 100.

Then in the save and load scripts I'd copy over a chunk that's already written for you where it saves a variable already and change the part where it says "tem = room" to "tem = global.vol". I'm not on a computer with Yuutu right now so I can't copy and paste it but you should be able to find it easily enough. And if you do that correctly the game will save and load this variable.

The only other thing you need to do is make sure that every time it's changed/loaded you set the volume to that number. So your code for volume change would now be something like:


--- Code: ---global.vol -= 1;
sound_volume(music,global.vol);

--- End code ---

And the you'd probably have to add "sound_volume(music,global.vol);" to the loadGame script too.

Ataosama:
Well, I tried what you said and a lot of other things and I keep breaking my game so I'm just gonna give up and try to edit the song, or I'm gonna work on that when I have more experience otherwise I'm gonna kill someone. Thanks anyway for your help :p

Navigation

[0] Message Index

Go to full version