0 votes

I've made a soundeffect and when my game hits its time to 0 i call that soundeffect.
This is My Script for the Control Timer:

func _process(delta):
    if Globals.timeLeft > 0:
        Globals.timeLeft -= delta
        $TimerCount.text = str(Globals.timeLeft)
        $TimerCount.text = "%d" % Globals.timeLeft
    else:
        Globals.timeLeft = 0
        MusicController.play_sfx()
        get_tree().call_group("Playeres", "game_over")
        get_tree().call_group("Enemies", "game_over")
        get_tree().call_group("GameOverGroup", "game_over")

It plays the Audio but it keeps giving a bug sound, always repeating and not playing the Audio fully.

in Engine by (133 points)

1 Answer

+1 vote

It's hard to say without more code, but...

With the code you posted, when your Globals.timeLeft value is <= 0, you'll start processing the else side of that code block. There, you set Globals.timeLeft = 0, play some music, and do some other things.

Now, until something resets Globals.timeLeft to a positive value again, every frame will process that else block of code. So, it'll continue to set Globals.timeLeft = 0, start playing your music again, and everything else there.

I'm not sure what the intent is here, but I assume you don't want to reprocess that else block in every frame after your counter reaches 0 - which is what's happening now.

by (10,892 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.