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

#1 2012-10-28 20:26:27

chibitan
New Scratcher
Registered: 2012-03-10
Posts: 2

making sprite appear randomely by clicking a button

I want to know how I can make a sprite appear by clicking a button in a random fashion.

Let's say I have ten sprites all in hide stage and a "Show Sprite" button. By clicking the Show Sprite button, I would like a randomly selected sprite to show up. Broadcast does not seem to work since it does not allow randomization.

Any help will be appreciated.

thanks.

Offline

 

#2 2012-10-28 21:00:36

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: making sprite appear randomely by clicking a button

when gf clicked
broadcast (pick random (1) to (x))//just drag a random into the dropdown

when I receive [1 v]
script


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#3 2012-10-28 21:12:51

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

Re: making sprite appear randomely by clicking a button

Here's something you could use:

Put this in the button sprite:

when gf clicked
set [show v] to (0)
forever
 if <(mouse down?) and (touching [mouse pointer v]?)>
  set [show v] to (pick random (1) to (10))//This randomizes what shows.
 end
And use this in the 10 randomly showing sprites:
when gf clicked
forever
 if <(show) = (1)>//1 for the first sprite, 2 for the second, ect...
  show
 else
  hide
 end
I hope that this helps!

Last edited by ErnieParke (2012-10-28 21:18:15)


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

Offline

 

#4 2012-10-29 01:01:00

chibitan
New Scratcher
Registered: 2012-03-10
Posts: 2

Re: making sprite appear randomely by clicking a button

zammer990 wrote:

when gf clicked
broadcast (pick random (1) to (x))//just drag a random into the dropdown

when I receive [1 v]
script

Thank you for your help.
Using a simple number in broadcast makes sense.

Offline

 

Board footer