I want to add sounds but when I do they play in a loop even if I try to change the code or add something different

And i dont know how to do that

Any help would do me fine

1 Like

The third argument of audio_play_sound controls whether or not it loops, set that to 0 or false. If it’s a long clip that you want to cut off before it plays the whole thing use audio_stop_sound.

1 Like


The code looks like this, should I add or change anything

You might be having the issue where it plays repeatedly because the if statement is true. A simple flag might help by checking if played yet, if not then play sound and change the flag so it doesn’t play again. Hope some of that helps :3

I would suggest using another variable to determine what state the player is in, then using that to control what happens at each stage so you can set the money threshold once in your create event and don’t have to search through the step event to find where it is if you want to change it.
Doing it this way also lets you easily find out when the player has transitioned to a certain stage, rather than just when they’re in that stage, which is when I imagine you want the sound to play.
If you combine that with the advice I gave you in the other thread, it might look something like this.


In this example the stage_threshold array would be something like [0, 500, 1000, 1500, …] for however many stages and values you have. Same with sprites, where it’s just [sprite_1, sprite_2, sprite_3, …].

I wish I could do that but my programing skills are very low and I dont know how to set it up from the start

No time like the present to learn! Arrays are a great way to store multiple related values, doubly so when you can use a for loop or a repeat loop to check through the whole thing in a couple lines of code. I suggest looking into how all three of those work in gamemaker: arrays, for loops, repeat loops.

You can also middle click on any function in gamemaker to open up the documentation that explains what the function is and how it works (assuming that it’s one of gamemaker’s default functions and not a custom one). Super handy for when you forget what something does or you’re following a tutorial that assumes you already know how to use it.

Just wondering, If it is a clicker game does that same code apply?

Yup! The type of game doesn’t really change what code you use, just how you use it. You’ll be using most of the same tools for almost any game you make (unless you use the built-in physics engine GM has, there’s a lot of stuff that’s specific to that).
The code example above is pretty close to what I’m using in my game actually, as long as you initialize all those variables in your create event (everything but the arrays can just be set to 0 initially) that exact code will work. The only thing to watch out for is making sure that both arrays are the same length, otherwise it’ll look for something that doesn’t exist and crash when you run the game.