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

#1 2013-04-13 16:46:06

FreaK001
New Scratcher
Registered: 2013-04-13
Posts: 15

Getting a sound to play, depending on which way the ball is deflected

Hey all,
           I am new to the scratch environment, however kind of getting to know it and just needed a bit of clarity really so I know what I am doing wrong!

I have a ball, which needs to move vertically down the screen (I have done this), the next part of the exercise, a red box is introduced onto the stage. I have to make this ball deflect off the box, either to 10 steps to the left or right (using the PICK RANDOM [] TO []) The y_position of the ball should not exceed -175. I have done this to the best of my ability and am getting frustrated right now.. The result of the PICK RANDOM [] TO [] is to be made into a variable.

Next step; Depending on whichever way the ball is deflected (left or right), a sound is to be played depending on which way the ball goes. I have attached a copy of my entire script, which does not want to go my way!

when gf clicked
hide
show
go to [x:(0) y:(170)]
point in direction [(180)]
set [whichWay] to <pick random (-90) to (90)>
repeat until <y position> = (-175)
if <(y position)> > (-175)
move (5) steps

Offline

 

#2 2013-04-13 16:50:28

FreaK001
New Scratcher
Registered: 2013-04-13
Posts: 15

Re: Getting a sound to play, depending on which way the ball is deflected

Hey all,
           I am new to the scratch environment, however kind of getting to know it and just needed a bit of clarity really so I know what I am doing wrong!

I have a ball, which needs to move vertically down the screen (I have done this), the next part of the exercise, a red box is introduced onto the stage. I have to make this ball deflect off the box, either to 10 steps to the left or right (using the PICK RANDOM [] TO []) The y_position of the ball should not exceed -175. I have done this to the best of my ability and am getting frustrated right now.. The result of the PICK RANDOM [] TO [] is to be made into a variable.

Next step; Depending on whichever way the ball is deflected (left or right), a sound is to be played depending on which way the ball goes. I have attached a copy of my entire script, which does not want to go my way!

when gf clicked
hide
show
go to [x:(0) y:(170)]
point in direction [(180)]
set [whichWay] to <pick random (-90) to (90)>
repeat until <y position> = (-175)
     if <(y position)> > (-175)
move (5) steps
if <touching colour> = red
     point in direction [whichway]
move (10) steps
point in direction (180)
if <y position> < -(90)
play note (64) for (0.5) beats
ETC

Offline

 

#3 2013-04-13 16:54:44

Hyperbola
Scratcher
Registered: 2013-03-15
Posts: 100+

Re: Getting a sound to play, depending on which way the ball is deflected

FreaK001 wrote:

I have attached a copy of my entire script, which does not want to go my way!

Here:

when gf clicked
hide
show
go to x: (0) y: (170)
point in direction (180 v)
set [whichWay v] to (pick random (-90) to (90))
repeat until <(y position) = (-175)>
if <(y position) > [-175]>
move (5) steps
end
end
And I agree, the scratchblocks syntax is quite prone to errors.


Tip of the whatever: Don't post in threads older than 2 weeks unless your post will actually be useful.
It's the last day of 1.4! *cries* (quote from NeilWest, rest by me) by the time you read this it probably will be 2.0  sad

Offline

 

#4 2013-04-13 16:56:49

FreaK001
New Scratcher
Registered: 2013-04-13
Posts: 15

Re: Getting a sound to play, depending on which way the ball is deflected

http://tinypic.com/view.php?pic=sb60d3&s=6

Offline

 

#5 2013-04-13 16:59:51

FreaK001
New Scratcher
Registered: 2013-04-13
Posts: 15

Re: Getting a sound to play, depending on which way the ball is deflected

the above was an error due to me pressing submit to quickly, the tinypic link is my script in the scratch environment

cheers

Offline

 

#6 2013-04-13 17:02:51

FreaK001
New Scratcher
Registered: 2013-04-13
Posts: 15

Re: Getting a sound to play, depending on which way the ball is deflected

http://tinypic.com/view.php?pic=sb60d3&s=6

Link to scratch script..

Offline

 

#7 2013-04-13 17:10:32

Hyperbola
Scratcher
Registered: 2013-03-15
Posts: 100+

Re: Getting a sound to play, depending on which way the ball is deflected

Oh ok, and I see you're making a new thread  smile

(Yes, being a new scratcher is too restrictive)


Tip of the whatever: Don't post in threads older than 2 weeks unless your post will actually be useful.
It's the last day of 1.4! *cries* (quote from NeilWest, rest by me) by the time you read this it probably will be 2.0  sad

Offline

 

#8 2013-04-13 17:14:14

FreaK001
New Scratcher
Registered: 2013-04-13
Posts: 15

Re: Getting a sound to play, depending on which way the ball is deflected

Didn't mean to create a new thread, tried to salvage whatever scratchblocks code I had to went back on the browser and hey presto.. a new thread!

Offline

 

#9 2013-04-13 17:19:31

Hyperbola
Scratcher
Registered: 2013-03-15
Posts: 100+

Re: Getting a sound to play, depending on which way the ball is deflected

FreaK001 wrote:

Didn't mean to create a new thread, tried to salvage whatever scratchblocks code I had to went back on the browser and hey presto.. a new thread!

Oh. Browsers can be weird.


Tip of the whatever: Don't post in threads older than 2 weeks unless your post will actually be useful.
It's the last day of 1.4! *cries* (quote from NeilWest, rest by me) by the time you read this it probably will be 2.0  sad

Offline

 

#10 2013-04-14 03:02:38

FreaK001
New Scratcher
Registered: 2013-04-13
Posts: 15

Re: Getting a sound to play, depending on which way the ball is deflected

Bump

Offline

 

#11 2013-04-14 11:33:08

FreaK001
New Scratcher
Registered: 2013-04-13
Posts: 15

Re: Getting a sound to play, depending on which way the ball is deflected

Plz help  sad  anyone...

Offline

 

#12 2013-04-14 11:42:54

echristophy
New Scratcher
Registered: 2013-02-28
Posts: 17

Re: Getting a sound to play, depending on which way the ball is deflected

What's happening when you run this script?

Offline

 

#13 2013-04-14 12:41:16

FreaK001
New Scratcher
Registered: 2013-04-13
Posts: 15

Re: Getting a sound to play, depending on which way the ball is deflected

The ball falls down the screen, hits the red box and deflects left or right which is required, it also does play a sound (as asked) but on occasion it bounces up and down on the box before it reaches the edge and plays the wrong sound?! It's real confusing because the script does work, but doesn't at other times! The only thing I can put this down to is the Pick random [] to [] block..

Offline

 

#14 2013-04-14 12:54:29

OverPowered
Scratcher
Registered: 2012-07-27
Posts: 100+

Re: Getting a sound to play, depending on which way the ball is deflected

Try this:

when gf clicked
show
go to x:(0) y:(175)
point in direction (180)
repeat until <y position < (-174)>
if <(y position) < (-175)>
set y to (-175)
end
if <touching color [red]?>
set [WhichWay v] to ((1) + ((pick random (0) to (1)) * (-2)))
change x by ((WhichWay) * (10))
play note ((60) + ((WhichWay) * (30))) for (0.5) beats
end
change y by (-5)
Additionally, if you have any additional problems, uploading your project would allow us to actually see and mess with the scripts ourselves. Thanks.  smile

Last edited by OverPowered (2013-04-14 20:22:06)


Newest project: Tunnel TEST ~http://blocks.scratchr.org/API.php?user=OverPowered&amp;action=onlineStatus~ On my mind: Unicameralism

Offline

 

#15 2013-04-14 13:49:51

FreaK001
New Scratcher
Registered: 2013-04-13
Posts: 15

Re: Getting a sound to play, depending on which way the ball is deflected

Hey OverPowered,
                           Thanks for your suggestion man, I appreciate it! I will try this now and see if it works! If I have any other problems then I shall upload my project!

Thank you very much

Offline

 

#16 2013-04-14 20:22:18

OverPowered
Scratcher
Registered: 2012-07-27
Posts: 100+

Re: Getting a sound to play, depending on which way the ball is deflected

Any luck?


Newest project: Tunnel TEST ~http://blocks.scratchr.org/API.php?user=OverPowered&amp;action=onlineStatus~ On my mind: Unicameralism

Offline

 

#17 2013-04-16 03:48:37

FreaK001
New Scratcher
Registered: 2013-04-13
Posts: 15

Re: Getting a sound to play, depending on which way the ball is deflected

No luck  sad  it worked, but not the way it should... I'm gonna upload my project! Thanks man

Offline

 

#18 2013-04-30 16:16:39

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Getting a sound to play, depending on which way the ball is deflected

If this question is about a homework assignment for a class - please make sure that asking for help in the forums doesn't violate any agreements you have with the teaching institution.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer