Discuss Scratch

NightSplat_School
Scratcher
3 posts

Pick random block keeps picking the same number.

I'm trying to make a script that randomly picks between 3 sprites, but the “Pick random from _ to _” block keeps choosing the same number every time.
whenclickedset(Sprite Picker)topickrandom1to3foreverifSpritePicker=1thenset(Sprite 1)to1ifSpritePicker=2thenset(Sprite 2)to1ifSpritePicker=3thenset(Sprite 3)to1
It picks one of the numbers and continues to choose that number whenever I restart the project.

Last edited by NightSplat_School (Oct. 1, 2022 03:36:40)

legendary34678
Scratcher
1000+ posts

Pick random block keeps picking the same number.

Could you please post your project link here? Your code should work fine as it is.
scratchgod2334
Scratcher
13 posts

Pick random block keeps picking the same number.

(comment helpful things here)
PutneyCat
Scratcher
500+ posts

Pick random block keeps picking the same number.

The problem is unlikely to be the “pick random” block itself. You can be pretty sure it is picking a random number 1-3 every time it is run.

The problem will be some other aspect.

It's hard to say what without seeing the actual code. But e.g.:

(1) What is resetting the Sprite1, Sprite2, Sprite3, variables? If they are all already set to 1 the code above doesn't really do anything.

(2) Do you have another green flag script? Bear in mind that you can't really control the order in which green flag scripts are run.

Incidentally, depending on what else is in your code, the forever loop may be unnecessary (and inefficient).
sCrAtCh_139508
Scratcher
100+ posts

Pick random block keeps picking the same number.

this code makes it so it never pickes the same sprite 2 times in a row
whenclickedforeverwaituntiltimetochangespritepickedsetsprite pickertopickrandom1to3repeatuntilnotoldsprite=spritepickersetsprite pickertopickrandom1to3setspritetospritepickersetold spritetospritepicker
Oumuamua
Scratcher
1000+ posts

Pick random block keeps picking the same number.

Hi, please, explain clearly that whst you want to achieve…
Greets

Last edited by Oumuamua (Oct. 1, 2022 18:19:42)

tank401
Scratcher
100+ posts

Pick random block keeps picking the same number.

have the set hing to random thing inside the forever thing
KRAZYKING1010
Scratcher
92 posts

Pick random block keeps picking the same number.

Put the set sprite picker inside the forever loop
_patipatibantyou_
Scratcher
27 posts

Pick random block keeps picking the same number.

test
cookieclickerer33
Scratcher
1000+ posts

Pick random block keeps picking the same number.

NightSplat_School wrote:

I'm trying to make a script that randomly picks between 3 sprites, but the “Pick random from _ to _” block keeps choosing the same number every time.
whenclickedset(Sprite Picker)topickrandom1to3foreverifSpritePicker=1thenset(Sprite 1)to1ifSpritePicker=2thenset(Sprite 2)to1ifSpritePicker=3thenset(Sprite 3)to1
It picks one of the numbers and continues to choose that number whenever I restart the project.
It’s not the random block, could you post the project ill be happy to help
NightSplat_School
Scratcher
3 posts

Pick random block keeps picking the same number.

sCrAtCh_139508 wrote:

this code makes it so it never pickes the same sprite 2 times in a row
whenclickedforeverwaituntiltimetochangespritepickedsetsprite pickertopickrandom1to3repeatuntilnotoldsprite=spritepickersetsprite pickertopickrandom1to3setspritetospritepickersetold spritetospritepicker
Thank you! I will post the project link for those who wish to know more information.

I won't change any scripts until I've gotten a for sure answer.
NightSplat_School
Scratcher
3 posts

Pick random block keeps picking the same number.

legendary34678 wrote:

Could you please post your project link here? Your code should work fine as it is.
https://scratch.mit.edu/projects/737255611

The people picker sprite has all the script I included in this post as well as the Abby, Dani, and Dee sprites.

I may have already found a solution but I haven't changed any scripts just to be sure.

Last edited by NightSplat_School (Oct. 3, 2022 15:23:31)

NightSplat
Scratcher
9 posts

Pick random block keeps picking the same number.

I have found a solution! I got rid of useless variables, and the “pick random” block works as intended now!

Here I have gotten rid of the forever script and put the individual sprite scripts below into each sprite based on their number.

whenclickedforeverifSpriteProcesser=1thensetAbby Placertopickrandom1to3stopThis Script

Thank you all so much for your help!

Last edited by NightSplat (Oct. 3, 2022 17:43:45)

NightSplat
Scratcher
9 posts

Pick random block keeps picking the same number.

This message and the one above were made using my main account. NightSplat_School is my school acount.

Powered by DjangoBB