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

#1 2013-01-17 20:25:43

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

I need help with using randomness, any help welcome.

Hi,

If you know of a good tutorial on the subject of random, please leave a link to it here.

If you know of any things to help me understand how to accomplish the following goal, please post.  smile


The Goal:

I want a sprite to fly across the screen at random times IF a level is started.
I want it to have three options, flying across the screen high, middle, and low.
I don't want it constantly flying across the screen, but i want the intervals of it showing up to a little random(Sometimes it flies across and again soon, sometimes a longer time period between each flight).

I hope that's descriptive enough,

Regards,


CAA14

Offline

 

#2 2013-01-17 20:42:31

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: I need help with using randomness, any help welcome.

That's quite easy to do, using the "pick random" block and knowing exactly what you want to do. c:

We have three options for altitude: Low, medium and high. So, the "pick random" block must pick between these three options, as numbers.

when I receive [fly v]
set [option v] to (pick random [1] to [3])
if <(option) = [1]> //low altitude
    set x to [-50]
end
if <(option) = [2]> //medium
    set x to [0]
end
if <(option) = [3]> //high
    set x to [50]
end
To make the script wait a random time, it's as simple as using the same "pick random" block as the parameter of a "wait" block, with the values you find appropriate:

when I receive [start level v]
forever //or until the level ends
    broadcast [fly v]
    wait (pick random [1] to [20]) secs
end

Last edited by technoguyx (2013-01-17 20:42:54)


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#3 2013-01-18 12:40:53

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: I need help with using randomness, any help welcome.

Hi,

Thanks for responding.

Thank you very much.  smile

I am implementing this code as soon as i finish this post.

regards,

CAA14

Offline

 

#4 2013-01-18 12:51:40

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: I need help with using randomness, any help welcome.

Edit:

I am new to scratch, but do know the core principles of programing.
I needed to know how to use random, and you helped me see how, thanks!

Regards,


CAA14

Offline

 

#5 2013-01-18 13:20:08

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: I need help with using randomness, any help welcome.

Hi,

Works like a charm.  big_smile
Thanks again, technoguyx!

Regards,

CAA14

Offline

 

#6 2013-01-18 13:54:22

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: I need help with using randomness, any help welcome.

Glad to hear that c: Have you used any other programming language, before Scratch? Just curious  tongue


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#7 2013-01-18 20:28:35

olayemi2003
Scratcher
Registered: 2013-01-18
Posts: 34

Re: I need help with using randomness, any help welcome.

i am a new scratch , and i want to ask ,how can we make parts of the body of the scratch

Offline

 

#8 2013-01-19 10:29:54

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: I need help with using randomness, any help welcome.

Hi,

To technoguyx:

I am currently learning Java, so kind of.  smile

To olayemi2003:

What exactly do you mean? Please clarify.

Are you asking if you can make several sprites and then piece them together?

Regards,


CAA14

Offline

 

#9 2013-01-19 18:53:32

olayemi2003
Scratcher
Registered: 2013-01-18
Posts: 34

Re: I need help with using randomness, any help welcome.

No,i mean how do we let  the part of the body of sprite move like the hand ,leg ,head  and other parts of the body

Offline

 

#10 2013-01-19 18:57:03

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

Re: I need help with using randomness, any help welcome.

olayemi2003 wrote:

No,i mean how do we let  the part of the body of sprite move like the hand ,leg ,head  and other parts of the body

Well if you want to do that, you're either going to need to create multiple costumes, or you'll have to turn the body part in question into a new sprite so that you can manipulate it.

I hope that this answers your question! Also, hello olayemi2003 and welcome to Scratch! I wish you much new found wisdom in the coming days!


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

Offline

 

#11 2013-01-19 19:22:33

olayemi2003
Scratcher
Registered: 2013-01-18
Posts: 34

Re: I need help with using randomness, any help welcome.

thanks for the answer,
but can you give an example of multiple costumes and where can we get multiple costumes.
thank you again for the answer

Offline

 

#12 2013-01-20 11:38:42

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: I need help with using randomness, any help welcome.

Hi,

olayemi2003,
Costumes are all within a sprite, they are created and edited in the "Costumes" tab, which is located besides the "Scripts" tab which is near the top of the screen.
They are like different poses in one sprite.

I believe, if you wanted to, make several sprites separately and then have them track to each other... I think, don't quote me on that... Like having the "arm" track to the "Body", though I've not tried that yet...

I hope that helped,

Regards,

CAA14

P.S. I'm working on a project right now, but after wards if you'd like i could try to implement that theory about the multiple sprites.

Offline

 

#13 2013-01-20 19:11:41

olayemi2003
Scratcher
Registered: 2013-01-18
Posts: 34

Re: I need help with using randomness, any help welcome.

thank you, i'look first .

Offline

 

Board footer