I doubt this is a bug with scratch, but I'm desperate for help. So here's my situation.
I have a sprite that needs to have a totally random costume. What I've done is "When I receive (broadcast), if random 1-5=1, change to costume #1. If random 1-5=2, switch to costume #2, etc., etc. However, at #5, I say "If random 1-5=5", than I list Three different costumes that are randomly picked from, dividing the chances that any of these will be picked by three (that's a one in fifteen, if you're wondering). But, the project keeps on picking the last one. It may be because, for that one, I've added "If pick random 1-3=3, and (variable)<17, switch to costume 7, else broadcast (broadcast message from sentence #2). I can post it as an incomplete project is anybody thinks it will help
Thanks,
Puddingreg
Offline
Oh, and to add, the variable that is smaller than 17 isn't limiting it. It's as if it didn't exist
Please help
Puddingreg
Offline
There's probably a lot of ways to do what you want...I like to do it this way. First, figure out what percentage of the time you want each costume to show...let's say you have 5 costumes and you want them to show in the following percentages: 5%, 30%, 20%, 44%, 1%
So, if you pick a random number from 1 to 100, then the ranges would be
Costume 1 - From 1 to 5
Costume 2 - From 6 to 35
Costume 3 - From 36 to 55
Costume 4 - From 56 to 99
Costume 5 - From 100 to 100
Notice that if you subtract the low end of each range from the top end and add one, you get the percentage that costume should be displayed. Now the code to set up the ranges, using nested if-then-else blocks, is:
[blocks]
<set{ N }to( <pick random( 1 )to( 100
<if><( N <<> 6 )>
<switch to costume[ 1
<else>
<if><( N <<> 36 )>
<switch to costume[ 2
<else>
<if><( N <<> 56 )>
<switch to costume[ 3
<else>
<if><( N <<> 100 )>
<switch to costume[ 4
<else>
<switch to costume[ 5
<end>
<end>
<end>
<end>
[/blocks]
Offline
Or:
[blocks]
<when green flag clicked>
<forever>
<switch to costume[ <pick random( 1 )to( 10 )) )>
<end>
[/blocks]
Last edited by Magnie (2009-04-22 09:14:13)
Offline
Magnie wrote:
Or:
[blocks]
<when green flag clicked>
<forever>
<switch to costume[ <pick random( 1 )to( 10 )) )>
<end>
[/blocks]
i dont think that would help
Offline
Magnie wrote:
Or:
[blocks]
<when green flag clicked>
<forever>
<switch to costume[ <pick random( 1 )to( 10 )) )>
<end>
[/blocks]
Your approach is fine if you are looking for each costume to be picked the same amount of times (on average). I was trying to describe a technique that allows you to specify unequal (and very customizable) costume usage.
Offline
Offline