playMaker

Author Topic: ArrayMaker: Extracting Values with "Contains Value" Actions  (Read 2373 times)

memetic arts

  • Full Member
  • ***
  • Posts: 141
ArrayMaker: Extracting Values with "Contains Value" Actions
« on: October 27, 2015, 11:51:09 AM »
Hi All -

I'm trying to connect the dots on certain pieces of how ArrayMaker works, and hoping someone can help.

In "plain" script, it seems to be a fairly straightforward operation to get isolated values associated with keys in a Hashtable, like this:

Code: [Select]
TestDef GetData(string byName)
    {
       if ( testsList.ContainsKey(byName) )
          return testsList[byName];
       return null;
    }

I've set up an FSM which loops through the items in a Hashtable, with key/values set up like this:

Key: thing1Loc    Value: Lincoln Center
Key: thing2Loc    Value: Central Park
Key: thing3Loc    Value: Lincoln Center
Key: thing4Loc    Value: Hudson Greenway
Key: thing5Loc    Value: Central Park

What I would like to do is pass a specific value to select, and for every match, generate an NGUI menu item.

Effectively, I'm building a tree-menu system for selecting a location, and then displaying all of the items associated with that location. In simpler terms, I think this amounts to a filter.

The missing piece for me is how to pass the specific value to select.  In the Action, I've assigned the value to a local var, which the action seems to want, but in printing to the console, it always returns the complete set of items in the hashtable (though in a strange order, but that's another topic altogether!).

I've attached a screenshot of the basic setup, including the results printed to the console.  Any/all help greatly appreciated!!


memetic arts

  • Full Member
  • ***
  • Posts: 141
Re: ArrayMaker: Extracting Values with "Contains Value" Actions
« Reply #1 on: October 28, 2015, 02:03:46 PM »
Sorry for the bump, but could really use some help . . . if further clarfication/simplification is needed, I'll certainly try...  thanks!!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: ArrayMaker: Extracting Values with "Contains Value" Actions
« Reply #2 on: October 28, 2015, 03:51:13 PM »
Hi,

 I am not sure what the problem is as I don't see the full content of the hashtable.

Hashtables are unordered ( unreliable as well), so it's a "feature" or a "bug" within the .net framework unfortunatly. A Hashtable order doesn't matter, as it simply helps storing key value pairs.


you may be simply missing one action, "HashTable Get"

once you know you have a match, you should have another state with "HashTable Get" where you use the key you have used to check if it's contained.

 however, I think your misunderstanding is that "HashtableContainsValue", check for the value, not the key. In your script example, you check by key. Do you understand this difference?

Bye,

 Jean


memetic arts

  • Full Member
  • ***
  • Posts: 141
Re: ArrayMaker: Extracting Values with "Contains Value" Actions
« Reply #3 on: October 28, 2015, 04:15:09 PM »
Thanks, Jean, yes I realized just after I bumped the post that I'd used "key" as the example rather than "value", but yes I get that.

I think the missing piece is  the need for the HashtableGet action. My assumption was that by iterating through the keys, and providing a value for what I wanted to match on value, that it would only "found" values would follow the "Match" event, while non-matches would flow to "Not Matched".  Apparently not the case!

So . . . I'll pursue using the HashtableGet action and will report back. 

Many thanks!!!

memetic arts

  • Full Member
  • ***
  • Posts: 141
Re: ArrayMaker: Extracting Values with "Contains Value" Actions
« Reply #4 on: October 28, 2015, 09:07:44 PM »
Ok, I've taken a look at Hashtable Get -- both Get Key and Get Key from Value -- and I'm not so sure that it's going to give me what I want, only because I really do want the value (not the key) -- and every time that value is matched (the order doesn't really matter), I want to create an object based on that value.

In the end, and to correct the code snippet I posted above, all I want to do is this:

Code: [Select]
foreach (string value in hashtable.Values)
{
            if(value=="Central Park"){
        Console.WriteLine(value);
            }
}

It is the "if" statement that I can't seem to get right.

I feel like I'm missing something obvious/basic, but experimentation thus far has yielded nothing. I'll keep ramming into the wall, and maybe a brick will shake loose.  :-)

Thanks again for the input, Jean, always valued and appreciated!

Cheers

==rr
« Last Edit: October 28, 2015, 10:09:28 PM by memetic arts »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: ArrayMaker: Extracting Values with "Contains Value" Actions
« Reply #5 on: October 29, 2015, 01:31:11 AM »
Hi,

 you also have an action called "HashTableGetKeyFromValue", this is likely what you'll need to use then.

 also, maybe you should swap your keys and values, if indeed you always refer to the value to find a key... unless you have other places where you know the key and wants the value... then it's a dilemna, but with the action above you'll be fine.

 Bye,

 Jean

memetic arts

  • Full Member
  • ***
  • Posts: 141
Re: ArrayMaker: Extracting Values with "Contains Value" Actions
« Reply #6 on: October 29, 2015, 04:09:35 AM »
I think I've solved this, but not in the way that I expected . . . it looks like in HashtableGetNext, the key and the value are automatically stored in the Result as variables (which, for some reason, took me a while to realize). All I had to do was insert a String Compare action, and that seemed to do the trick. I think I was expecting to be able to do that directly, without the need for the String Compare, but at this point, whatever works is fine with me!

Where that gets me, exactly, is another question entirely, but for now I've at least solved the immediate challenge of pulling a set of hashtable members based on a shared value.

Thanks again for the assist, Jean!
« Last Edit: October 29, 2015, 04:14:55 AM by memetic arts »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: ArrayMaker: Extracting Values with "Contains Value" Actions
« Reply #7 on: October 29, 2015, 06:22:21 AM »
Hi,

 Good, I am glad you found a way out of this.

 Bye,

 Jean