[Plugin] Hash table

Post your completed addons to share with the community

Post » Fri Jun 28, 2013 9:30 pm

Just wanted to say thanks for the plugin - it solved my problem here when trying to get a multidimensional dictionary to work. Great help!
Moderator
B
72
S
13
G
11
Posts: 900
Reputation: 11,783

Post » Wed Jul 17, 2013 2:54 pm

I've been looking for an answer in the manual, forum, and wikipedia, but I'm confused as to how all this applies to C2.

Can anyone break down why someone should use a Hash Table vs Array?

In particular if the number of entries is unknown at creation and you want fast searching of the contents.

Thank you for any input!
B
6
S
1
Posts: 29
Reputation: 658

Post » Wed Jul 17, 2013 5:05 pm

They are sort of meant for different things. You might use an array for a tile-based level editor or grid-based inventory. A hashtable or dictionary could be used for save data ("Lives","Level","Score",etc.). Just depends on which is more suitable for your needs.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Wed Jul 17, 2013 6:43 pm

Thank you @Tokinsom-

I'm trying to figure out what to use to create a Database to keep a list of cards. Each card has different values written to it for X number of different items [but maybe I will want to add more item types in the future].

The user should be able to look up a card by UID (if the user knows it), or by sorting for all the cards that contain N of an item type- via the List Control.

The user may also want to do a Search of these cards via TextBox, so I need to be able to search all of these cards and show to the user which Card(s) contains what they are searching for.

Any ideas as to how an Array vs Hash Table would work differently in my case?
B
6
S
1
Posts: 29
Reputation: 658

Post » Sat Aug 17, 2013 4:05 pm

This is an awesome plugin! Thanks a lot. Just what I needed to start generating random worlds.

One suggestion. It would be great if you could do:
[CODE]Set value at "position.x" to 1000 in current entry[/CODE]...and get {"position": {"x": 1000}} instead of {"position.x": 1000}

That way, it would work the same as:
[CODE]Set key "position.x" to 1000[/CODE]SirSpunky2013-08-17 16:07:18
B
18
S
3
Posts: 57
Reputation: 1,081

Post » Sat Aug 17, 2013 4:39 pm

Also, there seems to be a problem with "For each item in" when values are objects.

I can do this:
Set key "a" to 100
Set key "b" to 200
For each item in ""

But not this:
Set key "a.label" to 100
Set key "b.label" to 200
For each item in ""

The latter does not loop any items, even though key a and b exist.
B
18
S
3
Posts: 57
Reputation: 1,081

Post » Sun Aug 18, 2013 5:23 pm

I managed to fix the problems by editing rex_hash/runtime.js:

Set value at current entry, support for "."
1) Add at line 84 in function instanceProto._set_current_entey():
[code]this._current_key = key;[/code]
2) Replacing method at line 219 to:
[code]Acts.prototype.SetValueInCurHashEntey = function (key_name, val)
{
     key = key_name ? this._current_key + '.' + key_name : this._current_key;
          
     if (key != "")
     {
          var keys = key.split(".");             
          var last_key = keys.splice(keys.length-1, 1);      
          this._set_entry_byKeys(keys);
          this._current_entry[last_key] = val;
     }
};
[/code]
I also needed support for this in the Entry() expression so I did a similar fix there:
[code]Exps.prototype.Entry = function (ret, key_name)
{
     key = key_name ? this._current_key + '.' + key_name : this._current_key;
          
     if (key != "")
     {
          var keys = key.split(".");             
          var last_key = keys.splice(keys.length-1, 1);      
          this._set_entry_byKeys(keys);
          ret.set_any(this._current_entry[last_key]);
     }
};[/code]
Looping all keys
I fixed the loop issue by commenting out the following at two places, line 158 and 174:
[code]if ((typeof value != "number") && (typeof value != "string"))
    continue;[/code]Not sure why it was there, but maybe it was a useful feature for some to only loop through numbers and strings?

Finally, I did another change that was useful for me.

Get item count, return 0 instead of -1 when not exists
Changed at line 118 in function get_item_counts(), return (-1); to return 0;

This was useful for me because I often add items by numeric index, like a unique id, and I use the item count to get a good index value. I wanted the first iteration to return 0 instead of -1, that's why I changed it. I can still use key exists if I need to test if the value exists.
B
18
S
3
Posts: 57
Reputation: 1,081

Post » Sun Aug 18, 2013 10:05 pm

Rex you are on the tops of my list :)

I wanted to implement language support for my upcoming project. To do so I wanted language files. en.json and you get the drift :D

As usual I try to see if I can work with C2 default Plugins. But something in my head just broke.

"{""C2Dictionary"":""true"", ""Data"":{""didnot"":""work"" }"
I just finally had enough of this. This is all sorts of WRONG for what is supposed to be a JSON string. Besides that I might have made a small syntax mistake above. Trying to fight with C2 JSON was just too much.

So I just used HASH table. And I had a stumbling block to start with. The "initial data example in the box" indicates that the "{}" should be encased with a " ". That caused C2 Error. You might want to modify the help instruction to remove them. However

Your Hash table JSON import works as JSON data shuold be stored. You sir have designed a great plugin. Though I would appreciate reducing the number of categories as most of the functions don't need there own single catagory. Tends to create a verticle scrolling list rather than a nice horizontal layout.

but fantastic. You have saved a few years of my life by reducing stress :D
B
87
S
18
G
9
Posts: 2,455
Reputation: 14,834

Post » Wed Sep 25, 2013 3:51 pm

Hello Rex is it possible to make an for each with this data ?

{
"friends":{
              0:{
                  name:'fuu'
               }
              ....
            }
"something else":{
                   }
}

If I do, for each item in "" I don`t get any data(It doesnt even starts an loop) also for each item in "friends" don`t work
B
15
S
6
G
6
Posts: 512
Reputation: 5,550

Post » Thu Sep 26, 2013 2:00 pm

Anyone who could please help on my question below....

I am using this Hashtable plugin. I have some data stored in the hashtable something like this -

{"Q1":"first question - what are the things present here?",
"A1":"first answer,
"Q2":"second q",
"A2":"second a",
"Q3":"third question",
"A3":"third answer"}

Where my keystring is Q1, A1 and so on...However when I remove keystring and corresponding values of say Q2,A2, then I need to change Q3 to Q2, A3 to A2 and so on...Any idea how do I achieve this without going through the entire hashtable again?

Please let me know.
For game development / IT services contact - ravindra@actualconcepts.com

List of published iOS apps -
https://itunes.apple.com/us/artist/ravi ... d693234511
B
69
S
18
G
3
Posts: 332
Reputation: 6,783

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 4 guests