2019-07-30 08:06:58

If I use the sound.play_looped function, it is not easy to do things after it loops. For example, increase pitch after each loop, or increase an integer variable by 1. Well, I know it is possible, but I'm not sure of a good way to do it. May I please have some help?

2019-07-30 08:13:44

try this:

sound s;
void main()
{
s.play();
if(s.playing==false)
{
s.pitch++;
s.play();
}
}
----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-07-30 12:04:20

it worked. Thanks

2019-07-30 15:17:15

I was just about to suggest the almost exact same code as post two, before i saw that he already told you how, xd.

2019-07-30 23:20:55

and you could just add a counter if you want it to play a certain amount of times e.g:

sound s;
s.play();
int count=1;
if(s.playing==false and count<1010101001)
{
s.pitch__;
counter++;
s.play();
}
----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-07-31 13:01:51

Alternatively, try this:
double oldPos = -1, newPos;
while(true) {
newPos = s.position;
if(newPos < oldPos) {
// sound has looped, code goes here

}
oldPos = newPos;
}
The advantage of this code is that the sound will keep looping no matter what. So if for some reason there's a 40 ms delay in your program, the user won't notice because the sound will keep on going.

Roel
golfing in the kitchen