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)


Please help us to repeal article 13, or else europeans like me won't be able to use scratch!

This is my signature, it automatically appears under everything I say. To make your new signature now, go here: https://scratch.mit.edu/discuss/settings/yourusernamehere
Type in your username in the ‘yourusernamehere’ section of the url.
To tell if something is a signature, you should see a small faint gray line that separates my signature and my actual post
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.

PrincessFlowerTV ✿
; Teen ; Christan ; Homeschooled ; My blog ; Forum Helper ; Wiki editor ; Writer ; Artist ; Awkward ; Mildly dyslexic ; Girl ; PFTV Review Shop ;


GO 3.0! #TrustTheST
Thanks for the link!  It does look like this is a duplicate topic so I'll close it to keep the conversation all in one place. Please use the existing topic in the link above. -Paddle2See
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