Reputation: 67
The problem is if - else of gml , i have a conditional in if and it is true , so the else case must no enter, so in this case in the if and the else are working i dont know why. i have a global variable that is Turno. please check the code.
when i do click on a image it check if turno is 1 if turno is 1 so play a audio else do the switch case, but my code works both the if and the else case i dont know why.
THIS IS THE CODE OF ONE OBJECT AND THERE ARE ONE GLOBAL VARIABLE CREATED in this same OBJECT LIKE
it is created in create event.
Global.Turno = 1
this is the Left Button event. of the object.
if(global.Turno == 1){
global.Turno = global.Turno + 1 ; //ahora toca turno dos
global.Logros = global.Logros + 1 ; // ya paso la prueba de turno uno
// aqui reproducir el audio MUYY BIENNN.
if(!audio_is_playing(snd_muy_bien)){
audio_play_sound(snd_muy_bien,100,false);
}
}else{
switch(global.Turno){
case 1: {
if( !audio_is_playing(snd_encuentra_la_cama) ){
audio_play_sound(snd_encuentra_la_cama,100,false);
}
break;
}
case 2 : {
if( !audio_is_playing(snd_encuentra_el_televisor) ){
audio_play_sound(snd_encuentra_el_televisor,100,false);
}
break;
}
case 3 : {
if( !audio_is_playing(snd_encuentra_el_zapato) ){
audio_play_sound(snd_encuentra_el_zapato,100,false);
}
break;
}
case 4 : {
if( !audio_is_playing(snd_encuentra_el_nino) ){
audio_play_sound(snd_encuentra_el_nino,100,false);
}
break;
}
case 5 : {
if( !audio_is_playing(snd_encuentra_el_ropero) ){
audio_play_sound(snd_encuentra_el_ropero,100,false);
}
break;
}
case 6 : {
if( !audio_is_playing(snd_encuentra_el_perro) ){
audio_play_sound(snd_encuentra_el_perro,100,false);
}
break;
}
case 7 : {
if( !audio_is_playing(snd_encuentra_la_ventana) ){
audio_play_sound(snd_encuentra_la_ventana,100,false);
}
break;
}
default: {
if(!audio_is_playing(snd_ya_has_ganau_felicidades)){
audio_play_sound(snd_ya_has_ganau_felicidades,100,false);
}
}
}
}
THERE ARE NOT ERRORS , THE PROBLEM IS THAT BOTH IS WORKING THE IF AND THE ELSE CASE. I DONT KNOW WHY THANKS. IF YOU GUYS WANT MORE CODE PLEASE TELL ME THNAKS.
Upvotes: 0
Views: 1994
Reputation: 121
I Agree with @YellowAfterLife, but I do want to make note that you do have a default setting in your switch case
default: {
if(!audio_is_playing(snd_ya_has_ganau_felicidades)){
audio_play_sound(snd_ya_has_ganau_felicidades,100,false);
}
Which means that it will play the music no matter what. Another reason could be variable scoping, although I don't think that it is the main reason behind your issue. You could check if it is by moving the ++ variable to the bottom as such:
if(global.Turno == 1){
if(!audio_is_playing(snd_muy_bien)){
audio_play_sound(snd_muy_bien,100,false);
}
global.Turno = global.Turno + 1 ; //ahora toca turno dos
global.Logros = global.Logros + 1 ; // ya paso la prueba de turno uno
}
Upvotes: 0