Relative Content

Tag Archive for javascriptarraysobjectkeyprobability

Picking a random object inside an array based on probability stored in keys

I’m just learning javascript and one of my personal projects for learning is a rpg game. I’ve been trying to get this working for several days, using functions I’ve seen on stackoverflow and trying to edit them for my particular case, but nothing seems to work. The game is text based and now im working on a “loot system”, so what I’m looking for is something like this: When a “search” button is clicked, a function is activated that reviews the objects in a given array, and selects one object based on the probabilities. I assigned each object a key called por: and that is the probability I would like for said object to come out.