How do I retrieve values from Dictionary instance variables?

0 favourites
  • 11 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi,

    It's been awhile. I'm trying out the latest beta of Construct 2 and I'm trying to create a virtual QWERTY keyboard that as you enter, will detect Japanese kana characters in romaji and convert them to the right character. Ex: if I type in "ru", the game should detect and translate it to "る". So I'm trying to make use of the Dictionary object. Now, while I was able to input a series of romaji -> kana instance variables, I notice that I'm not able the use the Dictionary.Get('name') command. It always returns a 0. However, when I do get something when I use Dictionary.name.

    So for example, Dictionary.ru will return me "る". But Dictionary.Get("ru") will return me 0.

    I need to use the first method because my source is a hidden text element or global string variable that detects keyboard input.

    Any thoughts what my problem is here? Or maybe there's another way to go about this?

    Thanks!

  • Could you share your events for setting the dictionary?

    Either by screenshot or by sharing your capx?

  • Here you go.

    So as you can see, I've tried loading in the key-value pairs as JSON. Still wouldn't work. What I'm doing here is logging text into a text input field first before trying to see if Hiragana.Get (a dictionary) can work with the inputted keys. In this example, Hiragana.tsu works, but since this isn't what I need, .Get is what I'm trying to get working.

  • Yeah, I see why that doesn't work..

    Hirigana.tsu works because you are calling the instance variable.

    Not sure why you'd give the dictionary object all those instance variables, but ok..

    To do what you are trying it would probably be a lot easier to use an array..

  • Construct 2 doesn't accept just any JSON string, but wants it in a special format

    something like this, if I'm not mistaken

    {"c2dictionary":true,"data":{"n":"ん","na":"な"}}

    and so on

    If you have the full version of Construct 2, you can start your layout in debug mode and check out if the keys are filled with your json string's data - I think they aren't.

    Also note that on created does not activate for the dictionary if you don't create one via some event. If you don't create it, use "on start of layout" instead to add all the relevant keys to the dictionary from the json string.

    LittleStain: I think Dictionary is the right choice, since you have name -> value pairs. In an array, you would need to do a for each x and then first look up the correct row that contains the key, before you can retreive the value for it.

  • Looks like it's not being loaded? Key count is 0... Hmm.. I'm confused by that special json format. Which gets the double-double quotes?

  • sorry, it was a mistake by copy paste from another topic and then meedling within, here you can see the right format:

    {"c2dictionary":true,"data":{"n":"ん","na":"な"}}

    Also note that your on create trigger doesn't fire off, if you don't create another instance of this dictionary within an event of yours (and why would you). Use something like "on start of layout" or compare the keycount and if it is 0 for the dictionary, then do the json loading.

  • Looks like it's allergic to single quotes.. As for the JSON loading, do you know how to load up the JSON file after having imported it into the project files?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok, I'm up to the point where I can use Ajax plugin to load up the data into a text box... But for some reason, the Dictionary isn't "importing". I've got:

    on start of layout, AJAX -> Request Hiragana-data.json (tag: "hiraganaData")

    on "hiraganaData" completed, Hiragana -> Load from JSON string Ajax.lastData

    Am I doing the dictionary loading right?

  • Oh nevermind. I tried your sample and it worked. I thought the c2dictionary part was just a filler example

  • That's what I meant with the "special format"

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