Block Code Help (Randomizer)

Hello,
I’m making a randomizer that gives players different gadgets at the beginning of a game, and I’m wondering if I can condense my code (which I’m really bad at). Basically, each gadget has its own variable which represents the chance of getting that gadget, and then it compares the variable to the random integer selected to see if the player gets the gadget. The issue I ran into was comparing a range of potential integers to the random integer, because the chances of getting each gadget is different. For example, the variable “Slingshot” is set to 400, and the variable “Zapper” is set to 300, and the random integer could be anything between 301-400 but I wasn’t sure if my code was working. Anyways, here’s what I have, so any notes would be helpful.


I have to go somewhere so I’ll check the answers when I get back. Thanks for the help!

So broadcast message on channel:
create text with:
“wepon”
random 1-3
1 is zapper
2 is slingshot
3 is evil eye

Yeah, but the chances aren’t supposed to be equal.

Then 1-5
zapper is 1 and 2
slingshot is 3
you get the point

can’t this be easier

I guess, but this is the way I know how.

You don’t need to make variables for the gadgets, just put the numbers in manually.
example: Instead of making a variable called Zapper set to 300 and making an if/statement saying if Zapper is less than or equal to Random Chance, you could just ignore making the variable and just put if 300 is less than or equal to Random Chance.

1 Like

I mean, if both solutions work, it’s a question of which one is more efficient.

I guess the one without variable. Obviously, keep the Random Chance, you’ll want to compare the same number, it’s the other variables that don’t have to be made.

divide every number larger than 1 in that image by 100.

But here you always “get the zapper”

Ah. What about the rest?

I know! I already made a guide on this:

1 Like

Can I get the ideal percentages of each gadget so I can create a sort of blockcode representing it?

Sure, thanks!
Slingshot: 10%
Zapper: 50%
Evil Eye: 20%
P.M.L: 20%

I wrote this block code as some sort of way to simulate the RNG:

See, the issue is that since it’s less than or equal to, it triggers lots of them. If the integer is 100, then you would get every single gadget. I need a way to specify a range of values without that range being random. Thanks, though!

No, it DOES work, I can’t get a GIF to show you so I suggest making a new map, writing this code down onto a player triggerable trigger, and see for yourself.

Well, think about it. If the random number is 100, then every single gadget would be triggered because it’s less than or equal to.

The "If else"s take care of that, we’ll probably decend into a flame war if we keep talking about this, so I’ll just stop and figure out how to make a GIF to show you.