Discuss Scratch

ianmccarthyschoolacc
Scratcher
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.
MrDanglyLegs
Scratcher
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:

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
Scratcher
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
Scratcher
44 posts

making a percent chance for something to happen

MrDanglyLegs wrote:

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
Scratcher
100+ posts

making a percent chance for something to happen

ianmccarthyschoolacc wrote:

(snip)

thanks! this code worked very well!
You're welcome!
Lariczlotdx
Scratcher
1 post

making a percent chance for something to happen

ianmccarthyschoolacc wrote:

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.
si

Last edited by Lariczlotdx (Today 12:03:12)

Powered by DjangoBB