The Dink Network

How to keep a sound play in the background?

December 18th 2009, 05:15 AM
knights.gif
pathfinder
Peasant He/Him China
I love hanging ON LINE without doing anything... 
For example,let the sound of ocean keep playing,or wind blowing,and others...
I tried,but there is always some errors...
This is my first file:
void main(void)
{
int &wait;
loop:
&wait = random(3000,2000);
wait(&wait);
playsound(50,20000,0,&current_sprite,0);
goto loop
}
And when I attach it to a stone,the game just crashed...
Awk...
December 18th 2009, 05:27 AM
burntree.gif
Fireball5
Peasant He/Him Australia
Let me heat that up for you... 
There is a way... I wouldn't attach the sound or the script to a sprite though, when you do that the sound fades when you get further away, so if you wanted wind blowing, you might want it to be consistant throught the screen.

Also, I don't see why there needs to be a random wait time, but you might have some purpose or reason for that.
December 18th 2009, 05:29 AM
sob_scorpy.gif
DinkDude95
Peasant He/Him Australia
The guy with the cute D-Mod. 
Try something like this:

void main ( void )
{
 int &chk_map;
sndloop:
  playsound(##, #####, 0, 0, 0);
  wait(length of sound);
  &chk_map = &player_map;
  if (&chk_map != &player_map)
	kill_this_task();
  goto sndloop;
}


Attach this to every screen you want the ocean/wind blow on and it should work.

Just be sure to change the ##'s and the 'length of sound'.

EDIT: I'm pretty sure you can attach it to any sprites or just the base of the screen. What I've done when I do this, is:

int &lala = create_sprite(0, 0, 0, 0, 0);
sp_script(&lala, "script");
December 18th 2009, 05:33 AM
knights.gif
pathfinder
Peasant He/Him China
I love hanging ON LINE without doing anything... 
Of course,the waves won't hit the coast exactly 3 times a minute...So there must be a random time gap between two sounds.
December 18th 2009, 05:34 AM
knights.gif
pathfinder
Peasant He/Him China
I love hanging ON LINE without doing anything... 
Oh,thanks,you are really of great help.
December 18th 2009, 05:37 AM
knights.gif
pathfinder
Peasant He/Him China
I love hanging ON LINE without doing anything... 
Er...but...there seems to be some kind of...echo?
Or that's many sound plays onr after another?
December 18th 2009, 05:45 AM
sob_scorpy.gif
DinkDude95
Peasant He/Him Australia
The guy with the cute D-Mod. 
Hmmm... Did you set the wait(); to the same length as the sound?

EDIT: By the way, your first script might have crashed the game because your 'goto' line didn't have a semi colon. you had:
goto loop
you should have had:
goto loop;
December 18th 2009, 05:47 AM
knights.gif
pathfinder
Peasant He/Him China
I love hanging ON LINE without doing anything... 
Umm...does it matter?
December 18th 2009, 05:49 AM
sob_scorpy.gif
DinkDude95
Peasant He/Him Australia
The guy with the cute D-Mod. 
Yes, the reason it echos is because it's not waiting the full length of the sound, which means you have two instances of the same sound playing over the top. You must set the wait(); to either the same length as the sound or longer.
December 18th 2009, 05:51 AM
knights.gif
pathfinder
Peasant He/Him China
I love hanging ON LINE without doing anything... 
Ummmmmm...That's reasonable...
December 18th 2009, 05:51 AM
spike.gif
The script in the original post looks okay, except you're missing a ; after goto loop. Possibly, using &wait as the name of the local could also be problematic... but probably not.

If you attach that script to a sprite on a screen, it should work just fine, as long as you have a sound loaded in slot 50. Trying to play a nonexistant sound will crash the game.
December 18th 2009, 05:55 AM
knights.gif
pathfinder
Peasant He/Him China
I love hanging ON LINE without doing anything... 
It worked!!
Thank you!!
Er...All of you!