Discuss Scratch

30goldendonkey
Scratcher
39 posts

Percentage block

The block would look like this:

(() % chance of () else () )

Basically, this block would have certain percent chance of returning a value, and if it doesn't return that value, return something else. This could help in a lot of ways, since right now Scratch only has a pick random () to () block.

I made this block in TurboWarp and it works!

Last edited by 30goldendonkey (April 20, 2024 13:53:17)

GamesReinvented
New Scratcher
100+ posts

Percentage block

30goldendonkey wrote:

The block would look like this:

(() % chance of () else () )

Basically, this block would have certain percent chance of returning a value, and if it doesn't return that value, return something else. This could help in a lot of ways, since right now Scratch only has a pick random () to () block.

I made this block in TurboWarp and it works!

does it work for decimals?
30goldendonkey
Scratcher
39 posts

Percentage block

No, it only works with integers.

Last edited by 30goldendonkey (April 20, 2024 14:05:42)

medians
Scratcher
1000+ posts

Percentage block

30goldendonkey wrote:

No, it only works with integers.
If you are referring to the pick random block, that works with decimals too.
Za-Chary
Scratcher
1000+ posts

Percentage block

30goldendonkey wrote:

No, it only works with integers.
Wait, why? Unless I'm misunderstanding the block's function, it seems like this could work with decimals.
30goldendonkey
Scratcher
39 posts

Percentage block

It picks random from 1 - 100, so it doesn't pick any decimals.
30goldendonkey
Scratcher
39 posts

Percentage block

medians
Scratcher
1000+ posts

Percentage block

30goldendonkey wrote:

It picks random from 1 - 100, so it doesn't pick any decimals.
You have to use a decimal point or a decimal number, like this:
(pick random (1.) to (10)
Then it will generate decimals:

Last edited by medians (April 20, 2024 15:03:47)

30goldendonkey
Scratcher
39 posts

Percentage block

medians wrote:

30goldendonkey wrote:

It picks random from 1 - 100, so it doesn't pick any decimals.
You have to use a decimal point or a decimal number, like this:
(pick random (1.) to (10)
Then it will generate decimals:
Oh thanks
GamesReinvented
New Scratcher
100+ posts

Percentage block

define return ()
set [return v] to (::custom-arg) // not necessary, just because I prefer a return function
define (percent)% chance of (option1) else (option2)
if <((percent) mod (1)) = (0)> then
if <not <(pick random (1) to (100)) > (percent)>> then // if not > is same as less than or equal to.
return (option1)
else
return (option2)
end
else
set [return v] to ((length of ((round(((percent) mod (1)) * (1000000))) / (1000000))) - (2
if <not <(pick random (1) to ([10 ^ v] of ((return) + (2)))) > ((percent) * ([10 ^ v] of (return)))>> then
return (option1)
else
return (option2)
end
the return block isn't necessary, it just helps me understand the block better :P, the bottom part is solely for decimals. Shift + right arrow to see the entire script. You can increase the 100… * and / as it only allows for 6 decimals, but do you really need a percent like this: 19.38502385% …

Last edited by GamesReinvented (April 20, 2024 16:14:52)

Powered by DjangoBB