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

#1 2009-09-13 17:32:47

zacknopp
Scratcher
Registered: 2009-09-13
Posts: 2

Randomly play a Sound from List of Sounds

I'm trying to write a simple "spelling bee" in Scratch.
How can I randomly select a sound to play?
A Scratch list can randomly select only a number or string.

Offline

 

#2 2009-09-13 17:43:39

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: Randomly play a Sound from List of Sounds

this should be in All about scratch. But i'll answer. add all the sounds in the stage. create a list with all the names of the sound and do:
<play sound[ item any of list ]


Hai.

Offline

 

#3 2009-09-13 17:56:52

zacknopp
Scratcher
Registered: 2009-09-13
Posts: 2

Re: Randomly play a Sound from List of Sounds

oops all sorted now - each item in the list can be the name of the sound.

Offline

 

#4 2009-09-14 13:36:06

JSO
Community Moderator
Registered: 2007-06-23
Posts: 1000+

Re: Randomly play a Sound from List of Sounds

You could just do

Code:

play sound (random (1) to (the number of sounds you have))

PS: I am moving this to all about Scratch


http://oi48.tinypic.com/2v1q0e9.jpg

Offline

 

#5 2009-09-14 22:06:00

samurai768
Scratcher
Registered: 2009-07-21
Posts: 1000+

Re: Randomly play a Sound from List of Sounds

When (whatever button it is) is clicked/ When i recieve [whatever you broadcast to play music]
set variable songs to [pick random number 1- (how ever many songs you have)]
If [variable songs=1]
play song 1

If [variable songs=2]
play song 2

and so on.

Offline

 

Board footer