sound_volume doesn't work with value.

S

Spongyoshi

Guest
Hello! I have a problem with sound_volume in GM8.1
I have an objet that, when created, checks the value of the current event and gets the corresponding bgm in his variable "MyMusic" then plays it with sound_loop(MyMusic);
Afterward, I want to adjust the volume depending of another variable called MyCut to silence the music when needed (like when getting an item with it's own theme) with the following code:
Code:
if (MyCut == 0)
{sound_volume(self.MyMusic,1);}
if (MyCut == 1)
{sound_volume(self.MyMusic,0);}
The problem is that it doesn't work, the music doesn't change volume at all :(
Did I do something wrong? Is there something else I should address? Have another way of doing it?
Thanks for reading and I hope you can help me out! I'm getting close to ending my project and this error is a pain for me... I don't understand it! Especially since I already use sound_volume in my project and it works well!
 
D

Drepple

Guest
I recommend you use audio_sound_gain() to change the volume of sound that is currently playing. Note that the volume scale is linear, meaning a value of 0.5 would be half volume, which sound_volume()'s scale is not. The 'sound' functions of Game Maker are not as flexible or stable as the 'audio' functions (found here) and the only reason they still exist is so that older projects still work, though it is recommended you replace them and that you use the audio functions in the future. I couldn't even get sound_play() to work, so I wasn't able to test if audio_sound_gain() would work with it. I recommend you use audio_sound_play() anyways, which is guaranteed to work.

If you are having trouble with any function, use the YoYo games library, which can be accessed by pressing f1 while in Game Maker or by middle mouse clicking a function in your code. (Simply googling the name works too, of course)

Lastly, something completely different; you don't have to use 'self.' anywhere as Game Maker automatically assumes you are using a local variable unless you add 'other.', 'obj_player.', etc. in front of a variable. (So 'self.x' should be 'x'.) Of course this is just a recommendation and I doubt it has any impact on performance, but keeping your code clean will certainly increase your performance and it will save a lot of time travelling through a dimension of spaghetti code. :D

I hope I helped you out, good luck finishing your project!
 
S

Spongyoshi

Guest
I tried to find the audio_x functions but seems to me they've only been added in future versions of Game Maker as typing "audio_" doesn't propose me anything...
Also, I wasn't sure about that but thanks for the confirmation! I added "self." because it wasn't working and wanted to be sure it uses the local variable but yeah it didn't helped at all as you can see ^^'
Thanks for your post though :D As long as I figure out how GM8.1's sound function works, it should be done!
 

TsukaYuriko

☄️
Forum Staff
Moderator
Instance context is implicit, you don't have to specify it. There is only one case where prepending a variable with self changes the scope: When you declare a local variable of the same name with var inside of a with statement.

Is the audio in question in MP3 format? That's not supported by sound_volume according to the manual.
 
S

Spongyoshi

Guest
Yes it is in MP3! Oh really? Well thanks a lot for the info! I guess I'll have to find another way to cut the sound then...
Also, it is? Well I thought https://docs.yoyogames.com/ were pull out straight from the manuals so I guess not? :(
 

TsukaYuriko

☄️
Forum Staff
Moderator
That link is indeed a copy of the manual. It's the manual of GameMaker Studio 1.x, though, and you're using GameMaker 8.1.
 

FrostyCat

Redemption Seeker
People using legacy versions of GM should learn to use the F1 key for when official online copies of the Manual are too new. And don't even get me started about the unofficial adolescent-curated nonsense on Wikia and similar open-edit sites.
 
S

Spongyoshi

Guest
Okay I'm back here! I'm still having the same problem even after reading the manual but this time, it's a .WAV sound and the code is as follows:
Code:
Create: con = sound_loop (sound78); Volumey = 1; hspeed = 5; vspeed = 5;

Step: if (self.x < SoundLocation.x + 300 && self.x > SoundLocation.x - 300 && self.y < SoundLocation.y + 300 && self.y > SoundLocation.y - 300)
{if (Volumey != 1){Volumey +=0.1;}}
else if (Volumey != 0)
{Volumey -=0.1;}
sound_volume(con,Volumey);
This time however it actually shows up an error that the index is incorrect! And I don't understand why, I though I did everything well!
I just wanted a simple way to have the sound disappear when it's far away and gets back on volume when it's on screen so if you have a better idea, please lemme know! (Besides "upgrade to studio" since this is pretty much all that's left to code for this project atm)
 

TsukaYuriko

☄️
Forum Staff
Moderator
sound_loop does not return a value. There is nothing in the manual that hints at it doing otherwise.
 
S

Spongyoshi

Guest
So is it not possible to differentiate two instances of the same sound being played?
 
Top