Discuss Scratch

Themanhimself115
Scratcher
4 posts

Pick Random 1 to 10

I may be dumb about this question, but I can't seem to understand the pick random script. I've done some games using it, but can't seem to do the show and hide technique? I've tried ways to add “forever” or not. For people that are willing to help me, I'm using the top code as “When I receive.”

Thank you, Themanhimself115
scratch___user12345
Scratcher
1000+ posts

Pick Random 1 to 10

Are you saying you want it to be a 50/50 chance if it hides/shows? if so use this:
when I receive [ message v]
if <[0] = (pick random (0) to (1))> then
show
else
hide
end
xxthepowerful
Scratcher
44 posts

Pick Random 1 to 10

For example :
when green flag clicked
hide
wait (pick random (1) to (10)) secs
show

You can use the pick random block If for example you want something to hide and then wait a random time between for 1-10 sec and then show.
Themanhimself115
Scratcher
4 posts

Pick Random 1 to 10

My idea was mostly to make the enemy spawn at one of the four points on the map. Basically, I want it if this random doesn't do the right number, then it would try this random number, but if that number wasn't chosen, then it… etc.

link: https://scratch.mit.edu/projects/681037483/

Just go to the link and go to the enemy sprite and i guess try?

Thanks.

Last edited by Themanhimself115 (May 9, 2022 16:35:37)

deck26
Scratcher
1000+ posts

Pick Random 1 to 10

I suspect you're making the common mistake

if <(pick random (1) to (4)) = [1]> then

else
if <(pick random (1) to (4)) = [2]> then

else
if <(pick random (1) to (4)) = [3]> then

end

What you should have is
set [myvar v] to (pick random (1) to (4)) 
if <(myvar) = [1]> then
else
if <(myvar) = [2]> then
else
if <(myvar) = [3]> then

The second one only generates one random number which will have a value 1 to 4. The first generates multiple random numbers and hopes it eventually gets a match with no guarantee it will.



Last edited by deck26 (May 9, 2022 17:32:33)

KaaBEL-NOOB
Scratcher
64 posts

Pick Random 1 to 10

Do you mean choosing one of few starting positions by random index? I would recommend having list with the position values in pairs:
item 1 = x position of first spawnpoint
item 2 = y position of first spawnpoint
3 = x pos. of second
4 = y pos. of second
5 = x…
6 = y etc.
Then pick random block can even use lenght of list so you can easily add or remove new spawn positions. The position choosing script will look like this.
set [index v] to ((pick random (1) to ((length of [spawn pos v] :: list) / (2))) * (2))
set x to (item (index) of [spawn positions v] :: list)
set y to (item ((index) + (1)) of [spawn positions v] :: list)
show
tb361
Scratcher
1 post

Pick Random 1 to 10

can someone help me i need when this sprite clicked do random 1 to 10 how do i do it
The_Imaginarium
Scratcher
1000+ posts

Pick Random 1 to 10

tb361 wrote:

can someone help me i need when this sprite clicked do random 1 to 10 how do i do it
Please create a new topic instead of posting on an existing one if you need help. But to answer your question, have a “when sprite clicked” event block set a variable to random 1 to 10 and change whatever you need according to that variable. For example,
when this sprite clicked
set [variable v] to (pick random (1) to (10))
12435tryhgefbkudrhhc
Scratcher
31 posts

Pick Random 1 to 10

How can i use this block, It is very confusing
gsaa_711
Scratcher
1 post

Pick Random 1 to 10

if <> then
<(pick random () to (10)) = [1]>
hide
end

after that just arrange the blocks correctly

Last edited by gsaa_711 (April 21, 2024 08:20:09)

_-Wolf-Spirit-_
Scratcher
9 posts

Pick Random 1 to 10

I'm trying to do something where you use a list and you can put thing on the list when playing, and I need to figure out how to make it choose random 1 to the top number that is on the list.
MrKingofScratch
Scratcher
100+ posts

Pick Random 1 to 10

_-Wolf-Spirit-_ wrote:

I'm trying to do something where you use a list and you can put thing on the list when playing, and I need to figure out how to make it choose random 1 to the top number that is on the list.
(item (pick random (1) to (length of [list v] :: list)) of [list v] :: list)
The length of list block outputs how long the list is, or as you put it “the top number that is on the list.”
jediwolf3
Scratcher
1 post

Pick Random 1 to 10

set [ v] to (pick random (1) to (10))
Dagriffpatchfan
Scratcher
1000+ posts

Pick Random 1 to 10

say ()
Dagriffpatchfan
Scratcher
1000+ posts

Pick Random 1 to 10

when stop flag clicked
bloxyandbrew
Scratcher
100+ posts

Pick Random 1 to 10

deck26 wrote:

I suspect you're making the common mistake

if <(pick random (1) to (4)) = [1]> then

else
if <(pick random (1) to (4)) = [2]> then

else
if <(pick random (1) to (4)) = [3]> then

end

What you should have is
set [myvar v] to (pick random (1) to (4)) 
if <(myvar) = [1]> then
else
if <(myvar) = [2]> then
else
if <(myvar) = [3]> then

The second one only generates one random number which will have a value 1 to 4. The first generates multiple random numbers and hopes it eventually gets a match with no guarantee it will.



what this guy means is that the first one makes the deeper the ifs are, the rarer the chance, the second one always has an even chance for all of them.

Powered by DjangoBB