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


    even this isn't working.

    <img src="http://content.screencast.com/users/crhatfield/folders/Jing/media/61813015-f231-46a2-ba4c-2142caab5e06/2012-06-05_1036.png" border="0" />

    am I missing something? thanks :)

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

  • 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


    OK I removed all json except these 2 groups

         "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"

    and here is events I have setup.

    <img src="http://content.screencast.com/users/crhatfield/folders/Jing/media/8d975b78-3f47-43f6-a87c-b81d87272412/2012-06-06_0251.png" border="0" />

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

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Typo spotted: "Load hash table form JSON string" - "form" should be "from"

  • Update:

    • Fix typo
    • Add "expression:AtKeys", user could pass each key into each parameter.

    For example, HashTable["a"]["c"] --

    user could use






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



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

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

  • Nice! Thanks rex. I'll get right on it. :-)

  • Update:

    Add "expression:ToString" which could transfer hash table into JSON string.

    It could assign mulit-parameters or no parameter.

    • If there has no parameter, transfer current hash table saved in this hash table plugin.
    • If there has parameters, like
    Hash.ToString("a", 10, "b", 20)

    It will create a new hash table = {"a":10, "b":20}, then transfer it into JSON string.

    User could use this method to create JSON string of hash table in an single expression. It might be useful to pass parameters with string index into official function plugin's "expression:Call".


    <img src="http://i1081.photobucket.com/albums/j352/rexrainbow1/FnHash.png" border="0">

  • Update

    Add "action:copy" to update hash table by other hash table.

    Sample capx

    It provides 3 mode:

    For example, the original content of hash table (hash table A) is

    {"a":1, "b":1, "c":1}


    The copy source table (hash table B) is

    {"b":2, "c":2, "d":2}

    1. "Overwrite from hash B"

    The result after copying by this mode is


    2. "Merge new keys from hash table B"

    The result after copying by this mode is


    3. "Clean then copy from hash table B"

    The result after copying by this mode is


    The motivation of making this action is to be used in loading saving data (from webstorage, for example).

    When the structure of saving data was changed, designer might need to check the valid of key (if the key did not existed, assign a default value) to make sure the compatible between new structure and old saving structure.

    For example, the hash table A

    {"a":1, "b":1, "c":1}


    is the old saving structure, and the hash table B

    {"b":2, "c":2, "d":2}

    is the new structure,

    Designer need to use a condition to check if the saving data had key "d", return 2 and write into hash table A if "d" is not inside.

    Now designer could use mode 2 to fill the new key from hash table B, so that designer could get value without checking valid.

  • since nobody answered my in my "how to.." post i might as well take it to the source;)

    i'm a noob trying to hack an app together that uses data from TMDB's API but i can't figure out how to make the results it returns usable in C2.

    from what i read the hash table plugin is the best bet for working with JSON in C2.. but i cant get it to work :(

    lets say i make a search request for a person like that:


    what it gives me is:

    {"page":1,"results":[{"adult":false,"id":488,"name":"Steven Spielberg","profile_path":"/jRWARxzljSY8SbOKTludOSECdk7.jpg"},{"adult":false,"id":8700,"name":"Sasha Spielberg","profile_path":null},{"adult":false,"id":23965,"name":"Anne Spielberg","profile_path":null},{"adult":false,"id":54127,"name":"David Spielberg","profile_path":null}],"total_pages":1,"total_results":4}

    so right now i have a text input field wich modifies the search term of the request URL and the ajax object can request the the data from that URL no problem and from there i can load it into whatever i want.

    Now i'm stuck though.. nothing seems to want to work. i don't even get the "id" keys to work with me..

    my goal here is to get all the resulting persons names shown and made clickable in C2.

    any ideas where to look?



  • AlanSmithee

    1. get total result count

    2. use for loop to get each item by expression: Hash.AtKey


  • that works like a charm! thanks a lot..

    now i just have to really understand it;)

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