Simple "current room" question [SOLVED]

D

Dioramos

Guest
I try to make in-game music, if main menu - play 1 audio, if not - 2 audio. I tried "room_get_name":
//Create
var roomname = room_get_name(room);
if roomname == MainMenu
audio_play_sound(aMenuMusic,1000,true);
if roomname != MainMenu
audio_sound_gain(aMenuMusic, 0, 1000);

But i think this isn't working.

Now i try:
//Create
if (MainMenu)
audio_play_sound(aMenuMusic,1000,true);
if (!MainMenu)
audio_sound_gain(aMenuMusic, 0, 1000);

But audio is not playing. Im very stupid, pls help
 

Yal

šŸ§ *penguin noises*
GMC Elder
How about this? If statements gets unwieldy if you want to check for a lot of different single equalities, switch cases is more appropriate for your use-case. (Also the room names when used as variables are numeric, not strings, so comparing the room name to the room index, like you did, isn't gonna work)
Code:
switch(room){
  case MainMenu:
     audio_play_sound(aMenuMusic,1000,true);
  break;

  //You can have as many cases as you want for different levels

  default:
     audio_sound_gain(aMenuMusic, 0, 1000);
     //Put some level music here or whatever
  break;
}
 
D

Dioramos

Guest
How about this? If statements gets unwieldy if you want to check for a lot of different single equalities, switch cases is more appropriate for your use-case. (Also the room names when used as variables are numeric, not strings, so comparing the room name to the room index, like you did, isn't gonna work)
Code:
switch(room){
  case MainMenu:
     audio_play_sound(aMenuMusic,1000,true);
  break;

  //You can have as many cases as you want for different levels

  default:
     audio_sound_gain(aMenuMusic, 0, 1000);
     //Put some level music here or whatever
  break;
}
Thank you, now it works properly!
 
Top