I’m trying to figure out how to implement a simple “loot box”-style system where each item has a certain chance of being selected, and one item is picked based on those chances.
For example:
Rare Box:
Hat (common 40% chance)
Pants (uncommon 40% chance)
Shirt (rare 20% chance)
I read that this could be done using JavaScript, but I’m not sure how to approach it.
Would really appreciate any tips or examples of how you’ve implemented something like this!
Just a 1 min thought, so there might be best things to do.
You could attribute each item a numeric range according to their probability. Then when you need to pick which item is won, you just have to get a random number and see in which range it falls.
hmm okey so it would be a range and not a number? but in bubble generate random number you can’t select 1-100 correct? How would the workflow look like?
And lets say there are 3 items in one box that are Common, how to select a random one of these?
I hope this helps someone else who was struggling with this like I was!
It’s a really simple way to build a nice rarity-based random mechanic in Bubble.
Works great for games, collectibles, rewards, you name it!