Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how to make something with a certain percent chance happening
- kierash
-
2 posts
how to make something with a certain percent chance happening
I am making a turn based fighting game were hits can miss how do i do that
- Exhelah
-
100+ posts
how to make something with a certain percent chance happening
Concept: Have a variable assigned to a random value between 1 and 100. Then check to see if it is less than or equal to your percentage.
Blocks (percentage is set to 86% chance it will happen):
Blocks (percentage is set to 86% chance it will happen):
set [percentage v] to [86]
set [randomNumber v] to (pick random (1) to (100))
if <((randomNumber) < (percentage)) or ((randomNumber) = (percentage))>
do stuff
end
- Tropic
-
1000+ posts
how to make something with a certain percent chance happening
Concept: Have a variable assigned to a random value between 1 and 100. Then check to see if it is less than or equal to your percentage.
Blocks (percentage is set to 86% chance it will happen):set [percentage v] to [86]
set [randomNumber v] to (pick random (1) to (100))
if <((randomNumber) < (percentage)) or ((randomNumber) = (percentage)>
do stuff
end
Here's the same script but slightly smaller if you want the script to take up less space:
set [percentage v] to [86]
set [randomNumber v] to (pick random (1) to (100))
if <(randomNumber) < ((percentage) + [1])>
do stuff :: custom block
end
Last edited by Tropic (Oct. 1, 2014 16:17:56)
- kierash
-
2 posts
how to make something with a certain percent chance happening
THANK YOU GUYS
- SteveMinecraftson
-
8 posts
how to make something with a certain percent chance happening
YAS! IT WORKS!
- DrKat123
-
1000+ posts
how to make something with a certain percent chance happening
Please don't necropost. This topic is old. Remember to check the date of the post before posting. Thanks YAS! IT WORKS!
- flyingninjawolf24
-
1 post
how to make something with a certain percent chance happening
THANKS!
I really needed that percentage thing for my project
I really needed that percentage thing for my project

- BKFighter
-
1000+ posts
how to make something with a certain percent chance happening
| THANKS!
I really needed that percentage thing for my project
|
V
[Please don't necropost. This topic is old. Remember to check the date of the post before posting. Thanks
- PhoenixFireblade
-
23 posts
how to make something with a certain percent chance happening
what about just:
set [percentage] to [86]
if <(pick random (1) to (100)) < ((percentage) + (1))> then
end
- spoonie06
-
3 posts
how to make something with a certain percent chance happening
thanks! (I hope it still works
)

- PhoenixFireblade
-
23 posts
how to make something with a certain percent chance happening
your welcome!
- Greatguy123
-
500+ posts
how to make something with a certain percent chance happening
I realize this is old, but probably the simplest way of doing this is like this:
if <(pick random (1) to (100)) < (86)> then
Yay percentages // category=custom
end
- deck26
-
1000+ posts
how to make something with a certain percent chance happening
That gives an 85% since you exclude 86. I realize this is old, but probably the simplest way of doing this is like this:if <(pick random (1) to (100)) < (86)> then
Yay percentages // category=custom
end
Since I'm necroposting anyway, one solution to that is to use random 0 to 99 < percentage but that could still be misleading when you look at it later. I'd prefer to use ‘NOT (random 1 to 100 > percentage)’ which covers less than or equal to in one statement.
- Ijukay
-
1 post
how to make something with a certain percent chance happening
What does the, do stuff block do?
- deck26
-
1000+ posts
how to make something with a certain percent chance happening
Whatever you code it to do. All it means is, here's the general code to control things but you need to add the inner coding yourself. What does the, do stuff block do?
- Skelebrine4
-
5 posts
how to make something with a certain percent chance happening
when green flag clicked
say [I need help. I don't know how to make people just move around and by chance they will do it without specific coding.]
- JavierR100
-
500+ posts
how to make something with a certain percent chance happening
Please do not necropost and create an topic for the help! ugh.when green flag clicked
say [I need help. I don't know how to make people just move around and by chance they will do it without specific coding.]
- Discussion Forums
- » Help with Scripts
-
» how to make something with a certain percent chance happening