playMaker

Author Topic: Get the key of a hashtable by searching for a specific value [SOLVED]  (Read 1898 times)

mitchelq

  • Guest
Hello,

I'm trying to get the key of a hashtable by searching for a specific value, but I can't seem to find a way to do this.

I can do it the other way (by searching for a key and then getting the value of the key) but it seems impossible to get the key?

Example what I mean:
Keys / Values

enemy 1 / 10
enemy 2 / 15
enemy 3 / 12
enemy 4 / 8

I would like to get the highest number. I can get that by making an array of the values and sort it, but then I will still need to get the key to see which enemy it belongs to. The numbers/values do change every now and then.

Love to get some help on this.

Thanks in advance!

Best regards,

Mitchel
« Last Edit: March 28, 2014, 06:30:02 PM by mitchelq »

mitchelq

  • Guest
Re: Get the key of a hashtable by searching for a specific value
« Reply #1 on: March 28, 2014, 06:29:30 PM »
I found a way to go around the problem.

I now create an array from my hashtable which I sort, revert en get the highest value from. After this I go through my hashtable with the get next action and store the value as a variable which I compare to my highest value. If it matches I use the key and if not go to the next.

Not completely the right solution, but for now it works. If anyone has a better solution I'm still happy to hear so.

Thanks,

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get the key of a hashtable by searching for a specific value [SOLVED]
« Reply #2 on: April 08, 2014, 08:05:34 AM »
Hi,

It's all ok apart from the getting the key from the value on a hashtable. use "HashTableGetKeyFromValue" instead.

bye,

 Jean