1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Help with game over audio

Discussion in 'Programming' started by PlsHelpMe, Feb 17, 2019.

  1. PlsHelpMe

    PlsHelpMe Member

    Joined:
    Feb 17, 2019
    Posts:
    5
    I am working on a galaga style game. The player has 3 lives and dies after getting hit 3 times, but i want it to play an audio when he dies. i cant figure out how to do this and ive been to, too many forums trying to find a way to solve my problem but i havent found anything (sorry for my sloppy writing im just really tired and ive been working on this game all day). ive tried using audio_play_sound and sound_play, ive tried making it play when obj_player is destroyed and when my global variable for hp = 0. i tried to copy a line of code that i used to show the health bar when the player is alive but then show game over when it died, but replaced the code with playing music when the player is alive but then playing the game over sound effect when it dies. when the player is alive it plays the music its suppose, but not when it dies.
    (thx in advance for those that help)



    also heres the code

    if (global.dead == false)
    {
    audio_play_sound(snd_game, 10, true)

    } else {
    sound_play(snd_game_over);

    }

    when global.hp = 0 then global.dead happens
     
  2. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    463
    It's obvious, isnt it?
    Look at your else statement.
    sound_play is not even a function, unless you made a script called like that, it's audio_play_sound.
    You have it right in the if statement, use the same function and syntax.
    You will have to stop snd_game when snd_game_over is triggered, or they will both overlap.
     
  3. PlsHelpMe

    PlsHelpMe Member

    Joined:
    Feb 17, 2019
    Posts:
    5
    I've already tried that, and it didn't work, but thanks for trying to help.
     
  4. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    463
    Put
    Code:
    show_debug_message("game over music ON");
    in your else brackets.
    Run the game in debug mode, and when your player die, check if the message shiws in the debugger.
    If it does, your function is wrong, and if it doesn't, your event doesn''t trigger.
    That will narrow it down for the solution.
     
  5. PlsHelpMe

    PlsHelpMe Member

    Joined:
    Feb 17, 2019
    Posts:
    5

    Okay thanks. So it looks like my event doesn't trigger, do you know anyway that i could get it to trigger?
     
  6. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,662
    First off, @Taddio, sound_play() is a valid function, but it probably only works if you disable the New Audio Engine (the one that allows you to use audio_* functions).

    Second, what and where is the code that sets global.dead to true? Because if the message doesn't show up, then odds are you are never actually setting global.dead to true.

    Also, where is this code running from? If the code is in the player object and you destroy the player instance when he dies, then it won't be able to run the code because the instance was already destroyed.
     
  7. Taddio

    Taddio Member

    Joined:
    Nov 16, 2018
    Posts:
    463
    [My bad, I didn't realised the OP was on 1.4 and didn't know it was a build-in 1.4 function! Oops!
     
  8. PlsHelpMe

    PlsHelpMe Member

    Joined:
    Feb 17, 2019
    Posts:
    5

    the code where it plays the audio when global.dead = true is in an object that i made specifically for the game over audio called obj_death_audio. Also where do I disable new audio engine? Im very new to this, and thank you for helping.
     
  9. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,662
    You set it in the game settings. But the new audio engine works fine for you obviously, since music is playing.

    So, couple quick questions.So have you actually verified that global.dead is being set to true? When global.dead is set to true, you are destroying the player instance at the same time, are you not? At the time that global.dead gets set to true, do you do anything else which may prevent any other codes from running, such as restarting the room or leaving the room?
     
  10. PlsHelpMe

    PlsHelpMe Member

    Joined:
    Feb 17, 2019
    Posts:
    5

    global.dead does not destroy the player, but i actually found a solution to my problem and now i feel retarded. In my player object i had a step event that checked for when the player dies and then destroys the object (the step event did a few other things too). I then put in audio_play_sound(ect) and now it works, but thank you for helping me!
     

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