This site requires JavaScript, please enable it in your browser!
Greenfoot back
toba4366
toba4366 wrote ...

2018/4/27

How do I Array multiple sounds to randomly chose a sound and have the actor play the one chosen

toba4366 toba4366

2018/4/27

#
I need to make a button that will play one of six sounds when clicked but I am new to coding and don't understand arrays enough to figure out how to do so. My next question would be if I needed a person to hear that sound and click the corresponding actor most commonly associated with that sound how would I make it so that if they get it right it gets another random sound to play and how to make sure it doesn't do the same sound twice using arrays and stuff.
toba4366 toba4366

2018/4/27

#
how do I check if a sound has played also
danpost danpost

2018/4/27

#
One array for all sounds. One array for all buttons (same order as sounds). One Actor field for correct button (initially set to null). One int field to keep track of the count of how many sounds have yet to be played (initially set to number of sounds, or length of sound array). When Actor field is null and counter field is greater than zero, choose a random index for sound array using counter field as limit; then, move that indexed element of button to the Actor field, and play the cooresponding sound from the sound array; then swap that indexed element in both arrays with the last possible chosen one, currently indexed at one less than the to-be-played value, which should subsequently be decremented. When the correct button is chosen (which is best check on by the act method of the world), set the Actor field to null. You could show some type of confirmation that the correct button was clicked first, if you so desired.
toba4366 toba4366

2018/4/27

#
thanks
You need to login to post a reply.