Discuss Scratch

kierash
Scratcher
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
Scratcher
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):
set [percentage v] to [86]
set [randomNumber v] to (pick random (1) to (100))
if <((randomNumber) < (percentage)) or ((randomNumber) = (percentage))>
do stuff
end
Tropic
Scratcher
1000+ posts

how to make something with a certain percent chance happening

Exhelah wrote:

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

how to make something with a certain percent chance happening

THANK YOU GUYS
SteveMinecraftson
Scratcher
8 posts

how to make something with a certain percent chance happening

YAS! IT WORKS!
DrKat123
Scratcher
1000+ posts

how to make something with a certain percent chance happening

SteveMinecraftson wrote:

YAS! IT WORKS!
Please don't necropost. This topic is old. Remember to check the date of the post before posting. Thanks
flyingninjawolf24
Scratcher
1 post

how to make something with a certain percent chance happening

THANKS!
I really needed that percentage thing for my project
BKFighter
Scratcher
1000+ posts

how to make something with a certain percent chance happening

flyingninjawolf24 wrote:

THANKS!
I really needed that percentage thing for my project
|
|
V

DrKat123 wrote:

[Please don't necropost. This topic is old. Remember to check the date of the post before posting. Thanks
PhoenixFireblade
Scratcher
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
Scratcher
3 posts

how to make something with a certain percent chance happening

thanks! (I hope it still works )
ChocolateZA
Scratcher
20 posts

how to make something with a certain percent chance happening

nice
PhoenixFireblade
Scratcher
23 posts

how to make something with a certain percent chance happening

your welcome!
Greatguy123
Scratcher
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
Scratcher
1000+ posts

how to make something with a certain percent chance happening

Greatguy123 wrote:

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
That gives an 85% since you exclude 86.

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
Scratcher
1 post

how to make something with a certain percent chance happening

What does the, do stuff block do?
deck26
Scratcher
1000+ posts

how to make something with a certain percent chance happening

Ijukay wrote:

What does the, do stuff block do?
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.
Skelebrine4
Scratcher
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
Scratcher
500+ posts

how to make something with a certain percent chance happening

Skelebrine4 wrote:

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.]
Please do not necropost and create an topic for the help! ugh.

Powered by DjangoBB