2019-08-13 18:17:24

Hi.
So for a while now i've been trying to add a thing to my game where all the game's sounds will fade out and stay that way until they are faded back in, by which I mean they will slowly decrease in volume until they get to -20, and then stay there until the function to fade them back in is called, sort of like what stw does with sleep. However, I've been running into an issue, mainly that the sound just doesn't want to stay where it should. The sound will usually fade out for a second or two, then revert back to how it was, same with fading in. Here's my code, let me know what I'm doing wrong.

void fade_pool_out([email protected] pool, bool destroy=true)
{
int volume=0;
while(volume>-20)
{
volume--;
for (uint i=0; i<pool.items.length(); i++)
{
if (@pool.items[i].handle!=null)
pool.items[i].handle.volume=volume;
}
wait(20);
}
if(destroy)
pool.destroy_all();
}
void fade_pool_in([email protected] pool)
{
int volume=-20;
while(volume<0)
{
volume++;
for (uint i=0; i<pool.items.length(); i++)
{
if (@pool.items[i].handle!=null)
pool.items[i].handle.volume=volume;
}
wait(20);
}
}
Use the below link to get about 500 or so mb of extra dropbox space when you create an account.
https://db.tt/dDngEzFLo7

2019-08-13 23:27:33

Hi,
Your code practically seems right to me.
Check if you're running your code in a wrong place. Like what triggers your code and what stops it from being executing.
Do note that putting waits in a BGT script causes it it to freeze untill the waiting time is exceded, So don't overuse them.
Timers are a very good workaround when you want your script to be responsive while doing a progressive task at the same time.

Be  fair minded, and let people to think in the way they want to.
People don't see the world in the way you do!