GML [SOLVED] Why doesn't the "else" function work?

Dr_Nomz

Member
So I have this code, which works fine, but the one thing that doesn't work is if there isn't any ammo leftover.
See the code is like this:
Code:
if (global.inventory[i] == 7){
     n = min(global.inventory_count[i],500-global.equip_count[0],500);
     if n > 0 {
        global.inventory_count[i] -= n;
        global.equip_count[0] += n;
      }else //<<<<Important Part
         sound_play(snd_Empty);
    }
That runs the code, but if n isn't over 0, (like at 0) shouldn't it run that code in the ELSE statement? Or am I not understanding how this code works?
 
P

Pyxus

Guest
So I have this code, which works fine, but the one thing that doesn't work is if there isn't any ammo leftover.
See the code is like this:
Code:
if (global.inventory[i] == 7){
     n = min(global.inventory_count[i],500-global.equip_count[0],500);
     if n > 0 {
        global.inventory_count[i] -= n;
        global.equip_count[0] += n;
      }else //<<<<Important Part
         sound_play(snd_Empty);
    }
That runs the code, but if n isn't over 0, (like at 0) shouldn't it run that code in the ELSE statement? Or am I not understanding how this code works?
Your phrasing is kind of weird so let me know if I misunderstood you. That will work, and the else will trigger if n is any value less than 1 (0, -1, -2...). If the else isn't trigger then all it means is n keeps returning a value greater than 0. Use show_debug_message, to see if n ever equals 0.
 
Last edited by a moderator:

TheouAegis

Member
Only issue i can foresee is if n is 0 because the current weapon is already full. So in that case if n>0 is false, then check if global.inventory_count[ i ]==0 before playing the sound. But you'd have the sound playing at least. ... Does sound_play work by itself elsewhere, or do you have to use the audio_play_sound function?
 
Top