[Plugin] Hash table

Post your completed addons to share with the community

Post » Mon Jun 04, 2012 8:55 am

Hi rexrainbow,

Want to ask another thing, is it possible to 'for each item' of an array value?

For data something like:
[code]
{
"equip":[
    { "type": "weapon", "id": "SWORD-0000", "amount": 1 },
    { "type": "material", "id": "ORE-0000", "amount": 10 },
    { "type": "potion", "id": "HEAL-0000", "amount": 20 }
]
}
[/code]

I found that using "At" works if I include the index of array on the key:

[code]
HashTableChar.At("equip.1.type")
[/code]

shows the correct entry ('material').

I also notice that for each item works if I include the index of array:

[code]
For each item in "equip.2"
[/code]

Puts out the correct key and value.

But if I try:

[code]
For each item in "equip"
[/code]

Nothing shows.

Thankssoybean2012-06-04 08:55:48
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Mon Jun 04, 2012 9:01 am

Oh.. nevermind.. I found that PickKeys "equip" works, and inserts the indexes to an Array... AWESOME!
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Mon Jun 04, 2012 9:15 am

@soybean

Yes, this feature comes from your previous requirement.
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Mon Jun 04, 2012 9:31 am

@soybean

Would it be useful if hash table have a tree traversal for "for each item"?
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Mon Jun 04, 2012 10:12 am

Hi rexrainbow,

Do you mean something like JSONPath (http://goessner.net/articles/jsonPath/)? That would be great.. :D
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Mon Jun 04, 2012 10:19 am

@soybean

Uh, I could not implement XPath. I mean, travel all leaf nodes in a root.

For example:
[code]{
"equip":[
    { "type": "weapon", "id": "SWORD-0000", "amount": 1 },
    { "type": "material", "id": "ORE-0000", "amount": 10 },
    { "type": "potion", "id": "HEAL-0000", "amount": 20 }
]
}[/code]

Will get all string and number value if root is ""
key="equip.0.type", value="weapon"
key="equip.0.id", value="SWORD-0000"
key="equip.0.amount", value=1
key="equip.1.type", value="material"
key="equip.1.id", value="ORE-0000"
key="equip.1.amount", value=10
...
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Mon Jun 04, 2012 10:21 am

Wow.. that would be awesome too :D
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Tue Jun 05, 2012 6:18 am

hi, can you tell me what I might be doing wrong here screenshot

I originally had the for each stuff nested below the system=>ajaxData!="" stuff.. moved it down just to try something else.. the disabled append there under that system=>ajaxData!="" works btw; data is there.

[code]
{
     "cards": {
          "general`s sword 8": {
               "faction": "universal",
               "ready": "6",
               "type": "Equipment",
               "ability0": "Command All N",
               "ability0_rank": "2",
               "ability1": "",
               "ability1_rank": "",
               "show": "1",
               "attack": "",
               "health": "",
               "class": "",
               "image": "general_s_sword_8",
               "name": "General`s Sword"
          },
          "battle speech 4": {
               "faction": "universal",
               "ready": "2",
               "type": "Special",
               "ability0": "Gain Morale N",
               "ability0_rank": "6",
               "ability1": "Demoralize N",
               "ability1_rank": "3",
               "show": "1",
               "attack": "",
               "health": "",
               "class": "",
               "image": "battle_speech_4",
               "name": "Battle Speech"
          },
          .....
[/code]


Thanks!
- Cecilcrhatfield2012-06-05 06:23:59
B
4
S
1
Posts: 6
Reputation: 737

Post » Tue Jun 05, 2012 8:03 am

I usually put the for each item of hashtable as a sub-event for ajax on complete.. haven't tried hash on created, so not sure if that's the problem.
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Tue Jun 05, 2012 8:12 am

@crhatfield

Just like @soybean said. Using "for each item" after "on create" might be strange -- hash table is empty when creating.
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 1 guest