[Plugin] Hash table

Post your completed addons to share with the community

Post » Sun Apr 29, 2012 12:46 am

Update:

Add "action: remove value" to remove item in this hash table
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Fri Jun 01, 2012 10:46 am

Nice plugin, thanks for sharing :)

Question: for keys with object values, is it possible to get the key on each item? This is crucial for me because I have a list of items with keys for item id, something like:

[CODE]
{
"SWORD-000" : { "name": "rusty sword", "stat": { "DMG": 100 } },
"SWORD-001" : { "name": "dull blade", "stat": { "DMG": 200 } },
"SWORD-002" : { "name": "iron blade", "stat": { "DMG": 300 } }
}
[/CODE]

thankssoybean2012-06-01 10:48:25
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Fri Jun 01, 2012 11:06 am

I made a small modification on my own, the current purpose is to just show that the value is an object, so I can add a sub-event to detect and handle it properly

[CODE]
            this.exp_CurKey = key;
            this.exp_CurValue = value;
            
            if ((typeof value != "number") && (typeof value != "string"))
               this.exp_CurValue = "[!OBJECT]";
[/CODE]
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Fri Jun 01, 2012 11:15 am

@soybean

This plugin support "for each key", see this post
http://www.scirra.com/forum/plugin-hash-table_topic47637_post322689.html#322689

And thanks, I will add a condition to check if the key is existed.
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Fri Jun 01, 2012 11:42 am

Yeah, the problem is, in my data, root keys all have object values, so this will look like an error (nothing to show)

I'd also like to have a conditional to check if curKey has object value.. this would be helpful, so I can store the ids on an array and fetch the data directly from HashTable.

thanks!
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Fri Jun 01, 2012 11:57 am

Update:

- Add "condition: key exists" to check a key is existed or not.

- Add second parameter at "expression: At", the second parameter is a default value returned when key is not existed. For example
[code]Hash.At("a.c", 20)[/code]
if Hash[a][c] does not exist return 20 , else return Hash[a][c]


@soybean

It might have a better way to do that, I will think it again.rexrainbow2012-06-01 11:58:45
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Fri Jun 01, 2012 12:50 pm

Thanks! Both updates would be very useful :)

About my initial idea, instead of checking the value type (esp if it's an object), how about an action to list keys per 'layer' to an Array?

Let's say for data

[CODE]
{
"a": { "b":1, "c":2 },
"d"
}
[/CODE]

The action works something like:
If 'listKeys("", Array.X)' will insert "a" and "d" to Array, and if 'listKeys("a", Array2.X)' will insert "b" and "c" to Array2?

Thanks again :)soybean2012-06-01 12:51:12
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

Post » Fri Jun 01, 2012 3:00 pm

@soybean

Good idea, I will implement it in this weekend.
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Fri Jun 01, 2012 4:27 pm

Update:

Add "action:pick keys", to pick keys into an array object. See sample capx.
This action will set array size to (0,1,1), then push keys into array. Using "array condition: for each element X" to pick them.



@soybean
Here it is.rexrainbow2012-06-01 16:33:50
B
97
S
22
G
176
Posts: 4,108
Reputation: 103,019

Post » Sat Jun 02, 2012 12:27 am

awesome! thanks!
B
21
S
5
G
5
Posts: 58
Reputation: 5,232

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: xoros and 0 guests