• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Windows Problems getting audiogroups to play

LazyTomato

Member
I wasn't really sure if i should post this here or in the programming section, but this is a problem i've had exclusively with GMS2 so i guess this'll have to do
So my game has a variable called global.music, which I use to handle what music is playing, fade it in and out and other fancy things. The game starts up at an init room that runs a script to set up every important variable for the game, then goes to the next room instantly (i.e. the title screen).
This script, among other things, loads the two main audiogroups in my game (audiogroup_music and audiogroup_sfx)

Now, as soon as i get to the title screen, some creation code for that room is supposed to assign a sound to the global.music variable and play it (so audio_play_sound(mus_title,1,1) )

So the problem here is: The title music doesn't play at all. Rest of the sounds in the game play just fine as soon as I start playing, and sound effects work too, but the music that was supposed to play when entering the room just isn't there. And the thing is, the sound does play if i take it out of my custom audiogroup and back into audiogroup_default.
I've also noticed that manually going back to the title screen after changing rooms to an in-game room makes the music play regardless of audiogroup. So I'm assuming it has something to do with the first time I'm attempting to play the sound... Which is weird, seeing as I started this game on GMS1 before porting it to GMS2, and this same code used to work perfectly fine.

I doubt it'll help much but here's the code i'm running:
Code:
//game_init()
//First setup, AKA absolutely everything

audio_channel_num(64)

audio_group_load(audiogroup_music)
audio_group_load(audiogroup_sfx)
audio_group_set_gain(audiogroup_music,1,0)
audio_group_set_gain(audiogroup_sfx,1,0)
global.music=-1
global.music_battle=-1

globalvar battle_mode;
battle_mode=false //Determines if we're currently in a battle or not. Used for music changing and such.

//Control setup
enum key { left, right, up, down, attack, shoot, jump, pause, menu_enter, menu_back };
for(var i=10; i>0; i--) global.keys[i] = 0;

global.keys[key.left] = vk_left
global.keys[key.right] = vk_right
global.keys[key.up] = vk_up
global.keys[key.down] = vk_down
global.keys[key.attack] = ord("X")
global.keys[key.shoot] = ord("C")
global.keys[key.jump] = ord("Z")
global.keys[key.pause] = vk_escape
global.keys[key.menu_enter] = ord("X")
global.keys[key.menu_back] = ord("Z")

room_goto_next();
 

Ricardo

Member
I bet the audio group isn't completely loaded at the moment you're trying to play the music. You can check if that's the case using audio_group_is_loaded(groupID).
 

LazyTomato

Member
I bet the audio group isn't completely loaded at the moment you're trying to play the music. You can check if that's the case using audio_group_is_loaded(groupID).
Oh, audiogroups take a bit to load... i always assumed the game froze momentarily until they were completely loaded (which one would normally not notice since it'd be less than a second, and right as the game opens)

So, basically, all i'd need to do here is just make the game wait until the audiogroups are loaded before moving onto the next room, right?
 

Ricardo

Member
So, basically, all i'd need to do here is just make the game wait until the audiogroups are loaded before moving onto the next room, right?
Exactly! You can even monitorate the audio group loading process using audio_group_load_progress(groupID). Here you can read all about audio groups.
 
Top