Discuss Scratch

drakearcher
Scratcher
54 posts

Dynamic Pitch Help

I have a game where there are 21 buttons, and clicking them makes a different sound depending on the button. The middle/11th one makes a normal sound, each one below makes a progressively lower sound, and each one above makes a progressively higher sound. I don't want to have to make 21 different sounds, as that would take up a lot of project space. I have tried taking the number of the clone's costume and doing some stuff with it, but it never works.

Here is my script:
whenIstartasacloneforeveriftouchingmouse pointer?andmousedown?thenwaituntilnotmousedown?ifcostume#=11thensetpitchto0startsoundclickelseifcostume#<11thensetpitchtocostume#-11*10startsoundclickelseifcostume#>11thensetpitchto11-costume#*10startsoundclick

There are some red blocks in the script above because the “set pitch” and “start sound” blocks didn't exist in Scratch 2, but that's just visual.

In the order that the set pitch blocks are in, the 11th and the first 10 work fine, but the last 10 just copy the first 10. If I were to switch the set pitch blocks, the opposite happens.

Please help me, as this is very important for my project, and I don't want to have to make 21 sound files, and risk my game not being able to save.
RokCoder
Scratcher
1000+ posts

Dynamic Pitch Help

I suspect that all you need is -

setpitchtocostume#-11*10startsoundclick
drakearcher
Scratcher
54 posts

Dynamic Pitch Help

RokCoder wrote:

I suspect that all you need is -

setpitchtocostume#-11*10startsoundclick

I tried it, and it worked perfectly! Thanks a lot! Also, thanks for making it super simple, because I try not to make a habit of if-else loops within if-else loops.

Powered by DjangoBB