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

#1 2008-05-23 04:38:24

neilsomthing
Scratcher
Registered: 2008-05-23
Posts: 3

2 questions: please help!

first, Im making a game, and i want to do like shoots, that u need to load, and if u dont got shoots u cant shoot. ive allready maked the variable shoots. so i want to know how to do that if the shoots variable is not 0 u can shoot. oh and the shoot is the custume2 of the sprite of the man.
2. if i do pick random 1 to 2, can i control the chances of what the computer will choose? for exemple: 70% that it choose 1 and 30% that is choose 2..

Hope u understand.
Thanks.

Offline

 

#2 2008-05-23 05:18:17

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

Re: 2 questions: please help!

neilsomthing wrote:

first, Im making a game, and i want to do like shoots, that u need to load, and if u dont got shoots u cant shoot. ive allready maked the variable shoots. so i want to know how to do that if the shoots variable is not 0 u can shoot. oh and the shoot is the custume2 of the sprite of the man.
2. if i do pick random 1 to 2, can i control the chances of what the computer will choose? for exemple: 70% that it choose 1 and 30% that is choose 2..

Hope u understand.
Thanks.

1. You are going to need to test on the shoots variable and do things based on the value so you are going to have to use the 'IF block' or the 'IF Then Else block'

[blocks]
<if> <( <{ shoots }>   <>> 0 )>
<broadcast[  Fire a Bullet ]and wait c>
<else>
<say[ Darn...out of bullets!
<end>
[/blocks]

2.  To set up a 70%/30% probability, use something like this:

[blocks]
<if><( <pick random( 1 )to( 10  <>> 3  )>

    do the 70% stuff

<else>

    do the 30% stuff

<end>

Hope that helps.


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

Offline

 

#3 2008-05-23 07:46:47

neilsomthing
Scratcher
Registered: 2008-05-23
Posts: 3

Re: 2 questions: please help!

UMMM.. i didnt understand the the seceond thing. can u explain me without the blocks?

Offline

 

#4 2008-05-23 13:19:39

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

Re: 2 questions: please help!

I can try.  You want something to happen randomly but 70% of the time.  The computer only generates random numbers evenly...but if we ask it to pick a number between 1 and 10 there is a 70% chance that the number it picks will be greater than 3. 

Looking at it another way, It might come up with

             any of these number: 1,2,3 (3 chances out of 10 = 30%)

or it might come up with

             4,5,6,7,8,9,10 (7 chances out of 10 = 70%)

so if we let it pick a number between 1 and 10 and then check to see if the number it picked is greater than 3 (the second group), it will be true 70% of the time.  And, of course, false 30% of the time. 

I hope that makes it a bit clearer.


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

Offline

 

#5 2008-05-23 16:32:13

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: 2 questions: please help!

Paddle2See wrote:

I can try.  You want something to happen randomly but 70% of the time.  The computer only generates random numbers evenly...but if we ask it to pick a number between 1 and 10 there is a 70% chance that the number it picks will be greater than 3. 

Looking at it another way, It might come up with

             any of these number: 1,2,3 (3 chances out of 10 = 30%)

or it might come up with

             4,5,6,7,8,9,10 (7 chances out of 10 = 70%)

so if we let it pick a number between 1 and 10 and then check to see if the number it picked is greater than 3 (the second group), it will be true 70% of the time.  And, of course, false 30% of the time. 

I hope that makes it a bit clearer.

And you could do:
set variable to pick random 1-10.
If variable > 3
set variable to the number you want.

Therefore, if the variable is greater than three (which 70% of the time it is) it will become the number you want!

Offline

 

Board footer