[Plugin] Hash table

0 favourites
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • claudius139

    I'm not sure, I thought cocoonJS could not support AJAX yet. (Maybe I'm wrong) So designer could not get external data from network right now.

  • Hey Rex,

    What's the best way to sort a hash table by a key/pair. As I wanted to order them by date for example. Just means that when I display them by iterating through the hash their in the correct order already.

    Cheers.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • labithiotis

    There is no directly & simple way to sort by key/pair.

    A solution is using javascript injected into functionext plugin. Put the hash table on input parameter in json format, sorting in javascript function, return the sorted array (another hash table) in json format.

  • Hello,

    Can i have an array as a value to a key? If so how do i iterate through that array?

    Thank You.

  • Just wanted to say thanks for the plugin - it solved my problem here when trying to get a multidimensional dictionary to work. Great help!

  • 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!

  • 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.

  • Thank you

    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?

  • 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:

    Set value at "position.x" to 1000 in current entry

    ...and get {"position": {"x": 1000}} instead of {"position.x": 1000}

    That way, it would work the same as:

    Set key "position.x" to 1000
  • 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.

  • 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():

    this._current_key = key;

    2) Replacing method at line 219 to:

    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;
         }
    };
    

    I also needed support for this in the Entry() expression so I did a similar fix there:

    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]);
         }
    };

    Looping all keys

    I fixed the loop issue by commenting out the following at two places, line 158 and 174:

    if ((typeof value != "number") && (typeof value != "string"))
        continue;

    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.

  • 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

  • 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 doesn?t even starts an loop) also for each item in "friends" don`t work

  • 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.

  • Forget my post before changed it for my own so the plugins supports for me now:

    -> for each Object in object

    -> getCurValue also can give you an Object back

    -> with hash.loopindex you get the current loop

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)