I am kind of new to scratch, and I cannot find out how to make a sprite change to a random costume. Will someone tell me how please.
Last edited by quinnriley (2007-05-22 17:54:41)
Offline
Here's the easiest way I can think of:
Repeat ( Pick Random 1 to **X** ) <-- instead of **X** put the number of costumes
Next Costume
That way it switches to the next costume some number of times, maybe just once (the next costume) or maybe as high as the total number of costumes-- which brings it back around to the one it started with. If instead you put one less than the number of costumes for **X**, then it will always change & never be the one it started with.
I haven't tested it, but I bet that code might flash through the costumes when it switches. If that's not OK then it's a little trickier, but you could do it for instance like this:
Set variable to ( Pick Random 1 to **X** ) <-- put the number of costumes
If < Variable = 1 >
Set Costume to costume1
If < Variable = 2 >
Set Costume to costume2
etc! So it sets a variable to a random number, and then it goes through checking to see which number it was, and sets the costume to the one it picked.
Hope that helps, don't be shy to keep asking if I didn't explain well enough.
<3
Offline
Oh hey sorry! I was just playing with it & there's an even easier way. You can just drop a "Pick Random 1 to 10" block into the "Set Costume to ( )" block. I didn't know that worked! Yay!
<3
Offline
Thanks So Much!
I have one more question though. Could I make it pick out of only some costumes, but not a whole range of costumes? I am making an Animated Fortune Cookie, and I need it to pick from every other costume.
Last edited by quinnriley (2007-05-23 18:00:07)
Offline
I found out how. Here is the code
======
Set fortune to (random 1 to *)
Wait 1 sec
If <<fortune = 1> or <fortune = 2>>
Switch To costume |Fortune 1 Closed
Wait 0.5 Sec
Switch to Costume |Fortune 1 Open
=========
Thanks for showing me how to do random, Mungojelly
Oops, After some programing, I found you can take out the <( ) or ( )> block and it still works.
Last edited by quinnriley (2007-05-23 18:43:41)
Offline