• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML [Solved] How To Loop Audio For A Specific Amount Of Times

T

TheWinterBeast

Guest
Hello, how do I loop an audio track for a specific amount based on a variable?
Example of what I tried:
var replay_amount = 2; //Audio Will Loop Twice

But when I do :
audio_play_sound(snd_sound, 1, replay_amount); //It doesn't work

P.S. Also, how do I use the code section properly when posting something.
 
D

Dracodino300

Guest
For starters, the documentation shows that the 3rd input is whether the audio loops or not, not how many times it loops.
Also, a "var" might fall out of scope if you use them in different parts of your object, and definitely are if switching between objects. So for now, I'd remove "var" from that statement to make it more accessible.

The best way I can think of making it loop only a fixed number of times is to have a timer, set to the length of the audio. When it goes off, start the audio again (not looping) and reduce replay_amount by 1. If it equals 0, turn off the alarm permanently.

As for code blocks,

 
T

TheWinterBeast

Guest
For starters, the documentation shows that the 3rd input is whether the audio loops or not, not how many times it loops.
Also, a "var" might fall out of scope if you use them in different parts of your object, and definitely are if switching between objects. So for now, I'd remove "var" from that statement to make it more accessible.

The best way I can think of making it loop only a fixed number of times is to have a timer, set to the length of the audio. When it goes off, start the audio again (not looping) and reduce replay_amount by 1. If it equals 0, turn off the alarm permanently.

As for code blocks,

Hi, thanks for the help but is there a function that can store the length of a piece of audio to a variable?
 
D

Dracodino300

Guest
audio_sound_length
Multiply it by the room speed for the alarm.
 
Top