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

#1 2013-01-06 20:46:26

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Using pick_random block

hi guys, Happy new year to you all.

Im having some difficulties compiling a script and i was wondering if i could get some help?

basically, starting at 0, 170 i have a ball that i want to defend to no more than -175.
Hlaf way down i have a peg and when the ball gets as far as the beg i want the ball to randomly pick whether to go left or right (10steps either way).  Everythings ok until i get this far.  At first i was getting the sprite to randomly move but not to how i need it.

i need the sprite to hit the peg and either side step left 10steps or right 10steps.  After sidestepping the script will continue allow the ball to descend until i add another peg.

Hopefully that makes sense, apologise if it doesn't, im pretty new to scratch however im looking to learn as much as possible so i can pass on to my 13yr.

Look forward to getting some replies

Offline

 

#2 2013-01-07 06:23:31

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

Nobody? :-(

Offline

 

#3 2013-01-07 09:27:58

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

heres what my script looks like so far:

http://farm9.staticflickr.com/8493/8357088279_93a9d8ae7e_c.jpg

Offline

 

#4 2013-01-07 10:11:20

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Using pick_random block

What are those program starts and ends blocks? And it looks like you're actually using a program called Sense, which appears to be based on an old version of Scratch. In any case, i would recommend adding this:

if <(pick random (1) to (2)) = (1)>
change x by (10)
else
change x by (-10)
end

Offline

 

#5 2013-01-07 10:31:08

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

Hi there, thankyou for your help.  Yes, im using sense for some coursework and the start/End blocks are just for good practice..So ive been told, as the script advances it makes it clearer to see where things start and stop...Hopefully will gain a few brownie points none the less.

I will give your script a try.  i sat for so many hours yesterday and had so many different variations.  One pretty similar to your but just not quite there.

I'll report back sure.

Thanks again

Offline

 

#6 2013-01-07 10:50:25

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

Right, Im happy with that as it is now throwing the ball either left or right randomly.  Thank you.

What i did forget to mention however is that i need to store the results in what way it goes in a variable.

ive created a variable, whichWay but no results go into it.

Offline

 

#7 2013-01-07 10:59:51

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Using pick_random block

What are you doing? Replacing the old code i gave you with this should work:

set [which way v] to (pick random (1) to (2))
if <(which way) = (1)>
change x by (10)
else
change x by (-10)
end

Offline

 

#8 2013-01-07 11:17:26

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

right, i think that is it sorted now, when it goes left it shows 2 and right 1

Thankyou for your time

Offline

 

#9 2013-01-07 12:11:24

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Using pick_random block

You're welcome. Good luck with your course.

Offline

 

#10 2013-01-07 12:13:39

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

Thankyou
Thankfully (for me) this will be the only course with programming.  Im looking to major in server tech and networking however i still ned to understand should i want to do SQL.  I haven't even looked at what that involves however.

Thanks again

Offline

 

#11 2013-01-07 12:20:57

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Using pick_random block

I like SQL. I'm not quite sure how to do loops, conditionals, and related stuff with it, but i can select and update just fine, which is mostly what i need it for.
I think you also need some programming in order to do server tech and networking, but not much. I do server programming in PHP, for one thing. I use other languages for other purposes as well.

Offline

 

#12 2013-01-07 16:54:36

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

Yea it funny really. Ive already done my cisco ccent and will be doing my ccna after server studies and in regards to the lingo, i have no problem.  I think at times i tell myself programming is hard than it probably is, not that its easy but i just dont have a passion for engineering in that respect.

nice to talk to you, are you on twitter at all? I like to use twitter for tech updates etc

Offline

 

#13 2013-01-09 14:54:22

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

Sicmonster, are you there my friend. Need one last bit of help and thats my 5 days of constant work finished....Until the next assignment in 4 or 5 weeks. lol

Offline

 

#14 2013-01-09 15:41:06

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Using pick_random block

Yes? BTW, you can post it to anyone, in case the person who answered originally is not available.  smile

Last edited by scimonster (2013-01-09 15:41:46)

Offline

 

#15 2013-01-09 15:42:03

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

I now need to modify the program so that i moves in random directions when faced against many red peg in the shape of a triangle.  All in all i need to repeat approx 100 times, each time stamping the ball as it gets to the bottom but im having problems getting the ball to move further than the 1st peg

Offline

 

#16 2013-01-09 15:45:25

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

i know mate, i did just that but i wanted yourself as you were kind enough to help me the last night

Offline

 

#17 2013-01-09 15:49:24

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Using pick_random block

What's your new script?

Also, it might be better to move steps instead of gliding - maybe that way you won't have to code for every single possibility.

Offline

 

#18 2013-01-09 15:54:15

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

scimonster wrote:

What's your new script?

Also, it might be better to move steps instead of gliding - maybe that way you won't have to code for every single possibility.

I'll post it for you know, I was thinking that about the gliding and thats where i got confused.  the code wud be endless but what way do i incorporate the step blocks?  i think by doing what it the way i have its not really hitting the peg, more stopping at the co-ordinates which isnt right :-(

script to follow:

Offline

 

#19 2013-01-09 15:59:53

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

Here is what i have so far but like you say, the glide code is probably now wrong but i can amend previous questions i think:

http://farm9.staticflickr.com/8464/8364756425_272a42b2ec_b.jpg

Offline

 

#20 2013-01-09 16:06:45

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Using pick_random block

So i would suggest something like this: Start out at the top square, using go to x/y. Decide whether to go right or left. Then, you can glide either to (x+10)@(y-20) for right, and (x-10)@(y-20) for left. I'm not sure if it's an even 10px; you can try a few numbers to see how far apart they are.

I didn't realize that those blocks i commented on were comments - i thought the comment block was always gray.  tongue

Offline

 

#21 2013-01-09 16:07:16

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

Just thinking there, if i dont use glide, how can it give the falling sensation?  If i use the move block, it just puts it straight there rather than crawling down the screen.

Does that make sense?

Offline

 

#22 2013-01-09 16:23:08

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Using pick_random block

Lorddalron wrote:

Just thinking there, if i dont use glide, how can it give the falling sensation?  If i use the move block, it just puts it straight there rather than crawling down the screen.

Does that make sense?

Yes, it does, though actually you could use a go to block to make a smooth movement, though most people prefer to use a separate script like this:

when gf clicked
forever
 change y by (-1)//change to desired speed

Just to show you, here's another option:

when gf clicked
forever
 go to x: (x position) y: ((y position) - (1))//Change 1 to desired speed.

If you want to, you could combine this script with other scripts, but make sure that wherever you put it, there won't be a wait block (or wait of any kind) interfering. Also, if you haven't noticed this by now, you'll need to remove the forever block if you do that.

Anyway, I hope that this helps! Also, hello Lorddalron and welcome to Scratch! I wish you good luck on your project!


http://i46.tinypic.com/35ismmc.png

Offline

 

#23 2013-01-09 16:38:16

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

Hi Erne, thanks for welcoming wishes.

Im afraid youve got me stumped now..ive tied your code but the ball isnt going down the screen.  Im ready for the rope.  This is probably a 10min job that has had me going mad for two days

Offline

 

#24 2013-01-09 16:41:54

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Using pick_random block

Lorddalron wrote:

Hi Erne, thanks for welcoming wishes.

Im afraid youve got me stumped now..ive tied your code but the ball isnt going down the screen.  Im ready for the rope.  This is probably a 10min job that has had me going mad for two days

Hmmm... I'm wondering why this isn't working, though don't touch the rope; we'll get this up and running soon. So, could you provide an image of the code you're using? I think that the problem might be there because of how you put in my suggestion.

Oh, and your welcome.  smile


http://i46.tinypic.com/35ismmc.png

Offline

 

#25 2013-01-09 16:51:40

Lorddalron
New Scratcher
Registered: 2013-01-06
Posts: 27

Re: Using pick_random block

Put it like this, i need to have this done at some stage tonight :-)  Otherwise im going to register on a hanging rope website cos i dont think i could make one of those either. lol.  You know, than fancy one like in the movies..lol  Only joking

Take a look at this for now, the same image i posted to monster.

What i need to happen is for the ball to go from the top (0, 170) to the bottom (-175 at least).

on its way, the ball comes to the red pegs. As it comes to the peg, the random_pick block is introduced to make the decision of going left and right.  i did have this achieved in an earlier stage but now the final part has introduced multiple pegs which i just cant figure out.

To finish off, the test needs to be repeated 120 times for the sake of probability. Each time the ball gets the the bottom, via the random route, it gets stamped at the bottom and the balls pile up

Does that make sense?

I really appreciate your time by the way...

Offline

 

Board footer