Legacy GM sound_volume doesn't work with value.

Discussion in 'Programming' started by Spongyoshi, May 7, 2019.

  1. Spongyoshi

    Spongyoshi Member

    Joined:
    May 30, 2018
    Posts:
    36
    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!
     
  2. Drepple

    Drepple Member

    Joined:
    Dec 9, 2017
    Posts:
    43
    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!
     
  3. Spongyoshi

    Spongyoshi Member

    Joined:
    May 30, 2018
    Posts:
    36
    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!
     
  4. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,487
    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.
     
    Spongyoshi likes this.
  5. Spongyoshi

    Spongyoshi Member

    Joined:
    May 30, 2018
    Posts:
    36
    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? :(
     
  6. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,487
    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.
     
  7. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,175
    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.
     
  8. Spongyoshi

    Spongyoshi Member

    Joined:
    May 30, 2018
    Posts:
    36
    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)
     
  9. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,487
    sound_loop does not return a value. There is nothing in the manual that hints at it doing otherwise.
     
  10. Spongyoshi

    Spongyoshi Member

    Joined:
    May 30, 2018
    Posts:
    36
    So is it not possible to differentiate two instances of the same sound being played?
     
  11. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,487
    In GameMaker 8.1, no, it's not possible.
    In GameMaker Studio, yes, it's possible.
     
    Spongyoshi likes this.
  12. Spongyoshi

    Spongyoshi Member

    Joined:
    May 30, 2018
    Posts:
    36
    Alright I'll adapt accordingly, thanks for the answer!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice