[Plugin] Hash table

Post your completed addons to share with the community

Post » Tue Jun 05, 2012 4:31 pm

Thats actually where I had it originally.. but maybe setting ajaxData variable there and then looping in a sub is hte problem, will fiddle with that but change that sub up a bit and just use ajax.lastdata instead of setting a custom variable, etc.. Thanks for the tip guys, have a great week!

- Cecil

(edit)

even this isn't working.



am I missing something? thanks :)crhatfield2012-06-05 16:38:56
B
4
S
1
Posts: 6
Reputation: 737

Post » Wed Jun 06, 2012 4:01 am

Hi crhatfield,

Can you add another appendText right after the Hash load from JSON string? Just output the Ajax.LastData to make sure the data is loaded.

For the looks of it, it should be working. From my experience, most silent errors happen due to the incorrect JSON data, like forgetting a comma or putting a string value within "".
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Wed Jun 06, 2012 8:38 am

Hello Soybean.

Yeah it does and so does Hash.HashTableToString - must be something in that ajax, probably the special characters in the "indexes" - not something I can control directly, will have to map that seperately with a php script prior to importing it into the game.. from there I can clean those up. Thanks for your help. I'm just glad I have the syntax/usage correct. been one of those days :)

- Cecil
(edit)

OK I removed all json except these 2 groups

[code]
{
     "cards": {
          "buscador_v2e": {
               "faction": "mexica",
               "ready": "8",
               "type": "Unit",
               "ability0": "",
               "ability0_rank": "",
               "ability1": "",
               "ability1_rank": "",
               "show": "1",
               "attack": "2",
               "health": "5",
               "class": "Sniper",
               "image": "buscador",
               "name": "Buscador"
          },
          "pimiento_v2": {
               "faction": "mexica",
               "ready": "6",
               "type": "Unit",
               "ability0": "Poison N",
               "ability0_rank": "2",
               "ability1": "",
               "ability1_rank": "",
               "show": "1",
               "attack": "2",
               "health": "5",
               "class": "Enforcer",
               "image": "pimiento",
               "name": "Pimiento"
          }
     }
}
[/code]

and here is events I have setup.



no dice. *shrug* I had similiar problems with CSV and XML plugins, have yet found one that works for me to iterate data with..

crhatfield2012-06-06 08:53:30
B
4
S
1
Posts: 6
Reputation: 737

Post » Wed Jun 06, 2012 5:04 pm

Oh, I've tried it out and found what is wrong..

HashTable's 'for each item in' can only be used for keys with string or number values, not objects or arrays. The only thing you can do is have an action to 'Pick keys' from 'cards' and put it on an Array. If you try to for each that array, you'll have values that are keys beneath 'cards' (buscador_v2e and pimiento_v2). With that, you can for each the hash using 'cards.' & Array.CurValue

I hope that's clear enough
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Sun Jul 29, 2012 6:15 am

Typo spotted: "Load hash table form JSON string" - "form" should be "from"
B
21
S
5
Posts: 43
Reputation: 2,529

Post » Sun Jul 29, 2012 9:01 am

Update:

- Fix typo
- Add "expression:AtKeys", user could pass each key into each parameter.
For example, HashTable["a"]["c"] --
user could use
[code]Hash.At("a.c")[/code]
or
[code]Hash.AtKeys("a","c")[/code]



@cklester

Thanks.rexrainbow2012-07-29 09:11:05
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Mon Jul 30, 2012 6:25 am

Update

Add expression:ItemCnt, Keys2ItemCnt to get item count.
For example, hash = {"a":10,"b":20}
Hash.ItemCnt("") will return 2 (key = "" means root)
Hash.ItemCnt("a") will return 1


The assignment of key for mutildimation is the same as expression:Hash.At , Hash.AtKeys --
Hash.ItemCnt("a.b.c")
Hash.Keys2ItemCnt("a","b","c")rexrainbow2012-07-30 06:26:51
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Mon Jul 30, 2012 8:28 pm

rex, the expressions aren't coming up in my C2. Is there something I have to do to "update" C2's awareness of new plugin source?

I checked out the dates of the files in the archive and none of them are recent. Can you check that?

Thanks! :-)

UPDATE: Looks like my Firefox download cache was getting me. I downloaded to another path and it looks like I've got the updated files now. :-)
cklester2012-07-31 00:31:36
B
21
S
5
Posts: 43
Reputation: 2,529

Post » Wed Aug 01, 2012 12:55 am

@cklester provided me a nice idea about expression:ItemCnt, Keys2ItemCnt

Now the expression:ItemCnt will get the object from the key, then
1. if this object is null (key does not exist), return (-1)
2. if this object is a number or a string (this is not a object type), return 0
3. if this object is a hash or a list, return the count of keys (items) in this object.


For example, hash = {"a":10,"b":20}
Hash.ItemCnt("") will return 2 (key = "" means root)
Hash.ItemCnt("a") will return 0
Hash.ItemCnt("a.c") will return (-1)
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Wed Aug 01, 2012 3:36 am

Nice! Thanks rex. I'll get right on it. :-)
B
21
S
5
Posts: 43
Reputation: 2,529

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: Vol6tmetr and 2 guests