Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Top-down shooter development week 11 - Second signal

For a couple days, I worked to find a solution on the unfounded belief that GDScript has no easy way to pause before executing the next line. Eventually I double checked and found that there is, in fact, an easy way to pause before executing the next line. Feels like there's a lesson here.

I have been incorporating sound effects that were made, as I mentioned last time I hoped to do soon. Adding sounds in Godot is pretty straightforward, but some sounds were happening too frequently to play them every time without blasting the players' ears. For example, there are often dozens of small enemies on screen at once, and playing all their death sounds when you tear through them would get way too loud.

To get around this, I came up with a solution that works for my purposes as my first time dealing with this problem, but is surely very questionable. I made a global variable to track how many death sounds are currently playing, and to only play another one if that number is below some maximum. Each enemy would send a signal to add 1 to this variable when it played a sound. So far so good. Enemies were then supposed to send a signal to subtract 1 right before being deleted if they had played a sound.

The problem was that I couldn't get this second signal to reliably be sent to save my life. About 80-90% of enemies that had played sounds would send the second signal just fine, but the ones that didn't never gave up their space to the next sound. This effectively meant one fewer death sound could be played at once for the rest of the game.

I imagined the second signal was sometimes not being fully sent before the enemy was deleted, and I tried everything I could think of to give all the enemies enough time to send it. I even tried making the enemy invisible and unable to interact with anything for a full 10 seconds after sending the second signal before being deleted. This didn't work either, so the problem must have been completely unrelated, maybe some arcane interaction with all those signals.

In the end, I checked to see if there was a straightforward way for GDScript to wait, and there is:

await get_tree().create_timer(int).timeout

Now, the first signal causes the variable to add 1 and wait roughly the length of the death sound before subtracting 1, and the second signal is completely unnecessary.

Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.