Discuss Scratch

KrithiDaBrownie
Scratcher
4 posts

I need help with my RNG game.

Hello! I recently started to make a RNG game. The problem is that sometimes when you roll, it wouldn't show what you got. I don't know how to fix it. Any help is appreciated! Thank you! https://scratch.mit.edu/projects/1091477036/
abrakaidabra
Scratcher
500+ posts

I need help with my RNG game.

The when I start as clone block in the swords sprite. Sometimes none of the conditions are true, and so the clone won’t show. You’ll need an if block for each condition, or you could do something with a list idk
PutneyCat
Scratcher
500+ posts

I need help with my RNG game.

Have just a single pick-random-1-to-256 (let's call it ‘n’) and then use a bunch of nested if…else blocks.

set n to pick-random-1-to-256
If n > 127: switch to most common costume
else if n > 63, switch to second most common costume
…all the way down to…
else if n > 3 switch to third rarest costume
else if n > 1 switch to second rarest costume.
else switch to rarest costume.

Couple of notes:

The reason the above uses 127, 63 etc instead of 128, 64 etc is that the probabilities have to add up to 1 and you want to have your probabilities halving at each stage. You can't actually achieve that without a bit of a fidddle - e.g. 1/2 plus 1/4 plus 1/8 comes out only to 7/8. But if you make the half not quite accurate (5/8) it comes to 1.

You probably don't need the forever loop.
KrithiDaBrownie
Scratcher
4 posts

I need help with my RNG game.

Thank you!
abrakaidabra
Scratcher
500+ posts

I need help with my RNG game.

PutneyCat wrote:

Have just a single pick-random-1-to-256 (let's call it ‘n’) and then use a bunch of nested if…else blocks.

set n to pick-random-1-to-256
If n > 127: switch to most common costume
else if n > 63, switch to second most common costume
…all the way down to…
else if n > 3 switch to third rarest costume
else if n > 1 switch to second rarest costume.
else switch to rarest costume.

Couple of notes:

The reason the above uses 127, 63 etc instead of 128, 64 etc is that the probabilities have to add up to 1 and you want to have your probabilities halving at each stage. You can't actually achieve that without a bit of a fidddle - e.g. 1/2 plus 1/4 plus 1/8 comes out only to 7/8. But if you make the half not quite accurate (5/8) it comes to 1.

You probably don't need the forever loop.
A bunch of nested if-else blocks can get messy quick. A more organized version of nested if-else’s is a bunch of if blocks with a stop this script block in it.
if <condition :: custom> then
your code here :: custom
stop [this script v]
end
if <2nd condition :: custom> then
your 2nd code here :: custom
stop [this script v]
end
if <3rd condition :: custom> then
your 3rd code here :: custom
stop [this script v]
end
etc.

Powered by DjangoBB