Discuss Scratch

Eddomannen
New to Scratch
1 post

How to make character make random sounds as it moves?

Hi, just fooling around a little trying to make a character that maybe eventually can shoot against random enemies or something like that.

This is what happens when the left arrow key is pressed.
forever
if <key [left arrow v] pressed?> then
change x by (-10)
switch costume to [ v]
play sound (item (random v) of [list v] :: list)
end
end

It changes costume well (it looks like the character is now facing the left) and it also moves as I want, the only problem right now is the sound. It´s supposed to make a sound randomized from a list of four (I have a list of four sounds to make for each direction the guy can go in) but when I try it, it plays three out of four of the sounds at the same time and that´s not what I want!
Can somebody here help me identify the problem and tell me what I should do instead?

First post here, sorry if it´s unorganized
Thanks in advance~
/Edvin
FuturePr0
Scratcher
100+ posts

How to make character make random sounds as it moves?

That won't work, you don't need a list to do it. delete theat list and replace it with this:
play sound (pick random (1) to (1))  until done
you can change the max range. and min range.
Also, can you please share the project so we can help you more? and this should be on ‘help with scripts’.

Last edited by FuturePr0 (Feb. 8, 2018 11:31:46)


This is my signature, it automatically appears under everything I say. To make your now signature, go here: https://scratch.mit.edu/discuss/settings/yourusernamehere
To tell if something is a signature, you should see a small faint gray line that separates my signature and my actual post


I have reached 100 posts! my 100th post was posted at 12:30:46 PM on the ‘things i’m making and creating' section, You can find the topic here. I am VERY good and skilful at so many things. Also you should see this!

My FAVOURITE colour is Orange
PrincessFlowerTV
Scratcher
1000+ posts

How to make character make random sounds as it moves?

FuturePr0 wrote:

and this should be on ‘help with scripts’.
I agree. I'll report this to be moved for you.


~~ Christian ~~ Mildly Dyslexic ~~ Homeschooled ~~ Forum Helper ~~ Teen ~~ Skater ~~
deck26
Scratcher
1000+ posts

How to make character make random sounds as it moves?

You probably don't want the sound to be in the same loop as checking for the key press as either the sound will keep restarting or you'll have to tell it to play the sound until finished and can't detect any key press in the meantime. But are other keypresses going to use the same set of sounds or a different set?

Assuming any key press uses the same sound set you could use a variable to indicate whether something is playing.

set [playing v] to [0]
forever
if <key [left arrow v] pressed?> then
change x by (-10)
switch costume to [ v]
if <(playing) = [0]> then
broadcast [newsound v]
end
end
end

when I receive [newsound v]
set [playing v] to [1]
play sound (pick random () to (10)) until done
set [playing v] to [0]


Powered by DjangoBB

Standard | Mobile