[Plugin] Hash table

Post your completed addons to share with the community

Post » Wed Mar 06, 2013 12:11 pm

I have similar problem like @RedDragon, my data looks like this:

{"Question": [{"Sentence": "It is over there.","RightWord": "there"},{"Sentence": "Mr. Smith went to Washington.","RightWord": "Mr. Smith"},{"Sentence": "Hi my name is Jake.","RightWord": "hi"},{"Sentence": "We celebrate Christmas.","RightWord": "Christmas"},{"Sentence": "He wanted to climb Mt. Everest.","RightWord": "Mt. Everest"},{"Sentence": "I'm hungry.","RightWord": "I'm"}]}

But I am not able to iterate through it as I do not know the length. Only way I can think about is to use Hash.AtKeys("Question", i, "Sentence") and loop through i and check for null.

Do you think there is a better way ?

-Thanks
B
10
S
3
Posts: 69
Reputation: 1,590

Post » Wed Mar 06, 2013 2:27 pm

@rexrainbow Thanks, but I found an way to do what I needed using your plugin. I used the following:

For "" from 1 to Hash.ItemCnt("")
     do something with Hash.At((loopindex - 1) & ".id")
     do other things with Hash.At((loopindex - 1) & ".name")
RedDragon2013-03-06 14:28:46
B
7
S
1
Posts: 7
Reputation: 839

Post » Wed Mar 06, 2013 2:32 pm

@mchulet Check my previous post on this thread, I think you can use:

For "" from 1 to Hash.ItemCnt("Question")
    do something with Hash.At("Question." & (loopindex - 1) & ".Sentence")
B
7
S
1
Posts: 7
Reputation: 839

Post » Wed Mar 06, 2013 2:57 pm

@RedDragon

Great! I forgot that.
It is not design for list object, never mind, it could be used in this case, cool.
B
97
S
22
G
179
Posts: 4,125
Reputation: 104,557

Post » Thu Mar 07, 2013 12:22 am

Update

Now expression:ItemCnt will return list length directly.

Here is a sample capx to iterate a list object.
The content of this list is provided by @RedDragon
B
97
S
22
G
179
Posts: 4,125
Reputation: 104,557

Post » Thu Mar 07, 2013 1:06 pm

That worked for me, Thanks RedDragon,rexrainbow.
B
10
S
3
Posts: 69
Reputation: 1,590

Post » Tue Mar 26, 2013 3:31 pm

Hello, I'm having trouble with arrays using the HashTable. I basically want to take an array from my JSON file which I load from an external URL, and place all the items in an array in construct2. My array from my JSON file looks like this:

{
   "en": ["word1", "word2", "word3", "word4", ... "word103"]
}

From the trial and error i've done, when I set my debug text to HashWords.ItemCnt("en") it appears as 103, so it's noticing that there's 103 items in the JSON array. However, I don't know how to get those words, and put them into an array in construct, all on the X-axis.

Thank you for any help.
B
12
S
1
Posts: 29
Reputation: 908

Post » Tue Mar 26, 2013 11:21 pm

@Rogalog

To put array into array object, see this and this.
B
97
S
22
G
179
Posts: 4,125
Reputation: 104,557

Post » Thu Mar 28, 2013 2:28 pm

@rexrainbow

Awesome, thanks dude. Turns out I was using CurKey, instead of CurValue which was my main problem. Rogalog2013-03-28 14:28:40
B
12
S
1
Posts: 29
Reputation: 908

Post » Fri Apr 05, 2013 12:36 am

Update

Support save/load system (r124)
B
97
S
22
G
179
Posts: 4,125
Reputation: 104,557

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 2 guests