playMaker

Author Topic: Hashtable help/advice  (Read 2816 times)

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Hashtable help/advice
« on: May 27, 2014, 09:59:31 AM »
Hi,
Say if I have 100 players, each one has a name, strength, speed, stamina etc. And I want to store all this info into a hashtable using Arraymaker,  would that be done by entering each one into a text file? e.g.
Jack 50 3 65

Then get arraymaker to iterate through it to populate a list?
Also how much data can be stored into each key?
I've used Arraymaker lists before, but never a hashtable. Can someone help please.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Hashtable help/advice
« Reply #1 on: May 27, 2014, 11:38:49 AM »
Hi,

 no, that would not be efficient ( or at least not exactly like that).

 For this, I strongly suggest going for XmlMaker ( on the wiki add on page).

 Hashtable is simply a list where each value is assigned a "key" like so:

"bob" -> 12
"Jane" -> 20
"Mike" -> 30

that hashtable would be for example the ages of each persons ( key = person, value = age)

So for your case, either you will have a hashtable for each property ( on for stamina, one for speed, one for strength). but that's not really something I recommand if you are not fluent with complex used of ArrayMaker.

The big question is why do you want to store this, shoudl it be persistent, and should it be stored on the device/computer or online?

Bye,

 Jean

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: Hashtable help/advice
« Reply #2 on: May 27, 2014, 01:41:43 PM »
Hi Jean,
All I want it for is to randomly get a "character" data from a list at the start and at some points in game, and read the character name along with their stats.  So I can then use that data to set global variables to change the character. 
It would be stored on the device (I thought as a txt file or something)


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Hashtable help/advice
« Reply #3 on: May 28, 2014, 01:11:26 AM »
Hi,

 would it need to persist across session?

I would use a combination of easySave and ArrayMaker, that would be the easiest approach without strong confidence in using a database.


Bye,

 Jean

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: Hashtable help/advice
« Reply #4 on: May 28, 2014, 03:38:30 AM »
I only need to call the data from 1 entry in the database a few times. Basically I have one character that will change it's stats at runtime. So say "Jack" who's strength is 6 stamina 20 will change to "Peter" strength 10 stamina 70.
I need a lot of different characters in the database to call from. I don't know how easy save would do this?

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: Hashtable help/advice
« Reply #5 on: May 28, 2014, 09:53:04 AM »
Hi,

 would it need to persist across session?

I would use a combination of easySave and ArrayMaker, that would be the easiest approach without strong confidence in using a database.


Bye,

 Jean

Ok, thanks Jean.  Yes, it would need to persist across sessions and I'm thinking of purchasing EasySave, so that will help with that.
Just some questions I hope you can answer for me :-

There are 2 ways I can go:-

1.Create a hashtable with a value and key

or

2.Make a database with a name and other bits of data (XmlMaker maybe)

If I pick (1) is it possible to have a hashtable like this :-

"John" - 351070
where 35 could be "strength" 10 could be "speed" and 70 could be "stamina" ?

Can I get PlayMaker to do this? So it gets the 1st 2 digits, assigns that to a variable, then get the next 2 etc ?

Or if I pick (2) can I just simply make a file including all the data and just simply pull one of the entries from that?  So, there is no iterating through the data, just have the file at hand when needed.

Sorry for the longish post, I just want to get your advice first before I decide which way to go.
Thanks again.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Hashtable help/advice
« Reply #6 on: May 29, 2014, 02:41:40 AM »
Hi,

 Very bad idea to condense values like that :)

 Instead, prefer one hashtable per "property", where everytime the key is the player name or id, and the the value. So we would have:

Hashtable "Stamina"
"John" -> 30
"Mike" -> 20
"Jane" -> 10

Hashtable "Strengh"
"John" -> 100
"Mike" -> 80
"Jane" -> 100

Hashtable "speed"
"John" -> 1
"Mike" -> 2
"Jane" -> 3

use the "reference" property to explicity access these hashtables if they are on the same gameObject.

 Bye,

 Jean

Splankton

  • Sr. Member
  • ****
  • Posts: 268
Re: Hashtable help/advice
« Reply #7 on: May 29, 2014, 12:43:40 PM »
Ah, thanks Jean.  I didnt think of doing it that way. Makes sense.

Is there a way to get a random key/value in a hash table?

EDIT: I've found a way by adding them into an ArrayList, then using GetRandom from that.
« Last Edit: May 29, 2014, 01:10:24 PM by Splankton »