This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-07-30 11:31:41

SonicPopsDad
Scratcher
Registered: 2008-07-30
Posts: 41

Is there any way of interrupting music being played 'until done'?

Hi,

I've created a game... http://scratch.mit.edu/projects/SonicPopsDad/228307
The small problem I've got is that I'm looping techno music during the main game whilst the user is playing, but I've got no way of stopping it in mid-flow...

so basically I want to halt the game, but the music might need 8 seconds (the length of the sample) to continue before it can hand over to the next process.

is there anyway better to structure than this...?

until playing = 0
  play techno until done
(repeat)

play end music


cheers!

Offline

 

#2 2008-07-30 12:08:41

keroro645
Scratcher
Registered: 2008-06-07
Posts: 1000+

Re: Is there any way of interrupting music being played 'until done'?

Do you mean you want the music to stop playing when something happens.

Offline

 

#3 2008-07-30 12:20:29

SonicPopsDad
Scratcher
Registered: 2008-07-30
Posts: 41

Re: Is there any way of interrupting music being played 'until done'?

keroro645 wrote:

Do you mean you want the music to stop playing when something happens.

yup, that's what I'd like.

I should explain 'playing' is a global variable I switch to 1 when the user is playing the game, and is set to '0' when he/she runs out of power, and 'game over' gets displayed.

If I do

until playing = 0
    play techno
(repeat)

then it just plays the first note before starting again.

I wondered if I could do something like...

until playing = 0
   play techno

   count = 0
   until playing = 0 and count = 1000 (or whatever number of repetitions I need)
       change count by 1
   (repeat)

   if playing = 0
       stop script
(repeat)


but I'm worried the repetition count might be influenced by how much I'm stressing the computer do all the rest of the stuff... so I might start chopping the music off half way through, or leaving gaps between plays  sad

I can't try this now cos I'm at work  wink

Last edited by SonicPopsDad (2008-07-30 12:23:51)

Offline

 

#4 2008-07-30 12:33:10

keroro645
Scratcher
Registered: 2008-06-07
Posts: 1000+

Re: Is there any way of interrupting music being played 'until done'?

Use sensoring thats wat i do.Make a music variable.

<when green flag clicked>
<forever>
   <if><( <{ music }> <=> 1  )>
   <play sound[ techno]
   <end>
   <if><( <{ music }> <=> 2  )>
   <play sound[ end]
   <end>
<end>

Offline

 

#5 2008-07-30 12:46:42

SonicPopsDad
Scratcher
Registered: 2008-07-30
Posts: 41

Re: Is there any way of interrupting music being played 'until done'?

Ahhhhh, I get the reason...

when I tried a loop with a 'play techno' it also had some other commands it'd process in the loop, and it was doing *those* that stopped the music playing and restarted it from the beginning (which caused it to just stutter on the first note)

so if I have a loop where the *only* thing it does is play the music, then it'll work  smile

great - many thanks!


edit:  actually it didn't seem to work, it still seemed happy to stop itself and start the sample from the beginning again.

So I reverted to 'play sound until done' but also made use of the 'stop playing sounds' block which does a good job of cutting the longer samples in mid-flow!  So I'm much better off than I was  smile

Last edited by SonicPopsDad (2008-07-30 21:47:36)

Offline

 

#6 2008-07-30 23:02:53

keroro645
Scratcher
Registered: 2008-06-07
Posts: 1000+

Re: Is there any way of interrupting music being played 'until done'?

Yeah itryed that and it didnt work.Try downloading this project and look at the music scripts in the background.(If you still need help)

Offline

 

Board footer