playMaker

Author Topic: Get weighted random key from hash table  (Read 3345 times)

marv

  • Junior Playmaker
  • **
  • Posts: 50
Get weighted random key from hash table
« on: September 07, 2016, 07:11:43 AM »
Hi,

I'm currently working on a random event system for my game and an action to pick a random key from an arraymaker hash table with all the keys' values used as weights for the random pick would help greatly in reducing the overall complexity of the mechanic.

At the moment I work around this by assigning values to each event according to a variety of variables/flags and then sorting the events into categories from common to rare and then pick randomly from those subgroups which does work but isn't really as flexible as I would like it to be.

cheers


edit: alternatively if somebody has an idea for a similarly flexible way to do this with currently available actions/addons (which is doable for an amateur without programming background), I'd be very thankful for that as well.^^
« Last Edit: September 07, 2016, 12:19:08 PM by marv »

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: Get weighted random key from hash table
« Reply #1 on: September 07, 2016, 01:42:37 PM »
Have you tried the ecosystem. there is a random weight action in it. Also you can use an array table with the hashtable name.

Do random weight Int => get array index from random wieght int result then get hashtable name from array result then get hashtable data (something like than)

marv

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get weighted random key from hash table
« Reply #2 on: September 09, 2016, 04:43:27 AM »
Hey, thanks for the reply. :)

The problem with the "random weighted int" action (unless I am missing something) is that you have to predetermine the number of variables it works with.

However since I am working with a very flexible number of possible events (+allow adding more events through modding) that could potentially get triggered, this doesn't really work for me. (could be 5, could be 50, could be 200+)

I don't want to put a hard limit on it, which would enable me to work with the random weighted int action. I currently use the workaround of assigning each event to a rarity group array according to its weight (which can change due to other variables) and then choosing first a rarity group with the random weighted int action and then a random event from said rarity group array.

As I mentioned in my first post I have no programming background and haven't been working with playmaker for too long yet, so maybe I'm just not thinking right here.^^

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Get weighted random key from hash table
« Reply #3 on: September 09, 2016, 06:02:03 AM »
Hi,
I think your "workaround" is the best solution, if you want it to be flexible.

A flexible random weighted key action would be too complex as you want to have more or less than a certain amount and set a weight on it @ run time.

marv

  • Junior Playmaker
  • **
  • Posts: 50
Re: Get weighted random key from hash table
« Reply #4 on: September 13, 2016, 07:52:55 AM »
Alright, thanks for the input. Guess I'll stick to what I've been doing then. :)