Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » making a percent chance for something to happen
- ianmccarthyschoolacc
-
44 posts
making a percent chance for something to happen
heya, im making a game where you have a certain chance of something happening, and if the chance is hit, you win. so far, ive been able to gather decimals for each chance, but they look like 0.385363 (example), and i dont know how to convert that into a chance sort of feature. can anyone help?
both values end up adding to 1, by the way.
both values end up adding to 1, by the way.
- MrDanglyLegs
-
100+ posts
making a percent chance for something to happen
I'm not 100% sure what you're asking for, but this might fit what you need:
If you were just wanting to convert your decimal into a percentage, you just have to multiply by 100.
define Roll for (%) % chance
if < (pick random (0) to (99)) < (%) > then
set [good? v] to (1)
else
set [good? v] to (0)
end
If you were just wanting to convert your decimal into a percentage, you just have to multiply by 100.
- HedwigsHat
-
1000+ posts
making a percent chance for something to happen
i guess maybe use the floor and ceiling blocks because they round up and down decimals
([floor v] of (...))
([ceiling v] of (...))
- ianmccarthyschoolacc
-
44 posts
making a percent chance for something to happen
I'm not 100% sure what you're asking for, but this might fit what you need:define Roll for (%) % chance
if < (pick random (0) to (99)) < (%) > then
set [good? v] to (1)
else
set [good? v] to (0)
end
If you were just wanting to convert your decimal into a percentage, you just have to multiply by 100.
thanks! this code worked very well!
- MrDanglyLegs
-
100+ posts
making a percent chance for something to happen
You're welcome! (snip)
thanks! this code worked very well!
- Lariczlotdx
-
1 post
making a percent chance for something to happen
si heya, im making a game where you have a certain chance of something happening, and if the chance is hit, you win. so far, ive been able to gather decimals for each chance, but they look like 0.385363 (example), and i dont know how to convert that into a chance sort of feature. can anyone help?
both values end up adding to 1, by the way.

Last edited by Lariczlotdx (Today 12:03:12)
- Discussion Forums
- » Help with Scripts
-
» making a percent chance for something to happen