How do I get my dictionary to work properly?

0 favourites
  • 5 posts
  • I am running into a strange issue using the dictionary object in my licensed version r262 of Construct 2. I am not sure if this is the right place to post this so I apologize in advance.

    I have a text file that will include the identification as well as a "tooltip" that goes with it. I brought the text file into the dictionary via AJAX using "tokenat". If I look in the debug panel, the dictionary is being created correctly.

    I have a textbox with a default text value but I want certain sprites (with "identification" instance variables) to be hovered over thus changing the text with a mouse-over event after comparing the variable to find which associated tooltip it requires.

    The problem is, the one with the key index of 0 works perfectly but anything else returns 0 (which according to documentation means that the key was not found). I have quadruple checked to make sure that the instance variable matches with that of the key that it is supposed to call.

    I created an example capx from scratch to show that the issue is able to be replicated and that nothing else is added to chance any kind of conflict. It is not allowing me to attach the example capx to this thread but if I need to I can send it to someone directly. I have also tried using arrays instead of the dictionary object but the issue persisted. I did notice that adding the 2 example keys and values in manually via actions caused it to behave correctly but as I will have a large number of tooltips, I would much rather store them in a text file if possible. I am just not sure as to why the issue comes up if the resulting dictionary is identical either way.

    Any help would be greatly appreciated. I have been stumped on this for about 2 hours now and I am running out of hair to pull out.

  • You need to upload your capx to some file sharing service like dropbox and post the link here.

  • ufile.io/zuowq

    Here it is. Thank you. At 4am that didn't really cross my mind.

  • Your text file contains line breaks. When you use tokenat() with ";" separator, the next token includes line break from the previous line. So your "glow" key actually looks like this:

    "
    glow"

    You need to add trim() to your expression to remove all line breaks, spaces, tabs etc from the beginning and end of the string.

    Or you can remove “;” and use line breaks to separate keys:

    tokenat(tokenat(AJAX.LastData, loop, newline), 0, "|")

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You need to upload your capx to some file sharing service like dropbox and post the link here.

    Always post a capx / c3p example. This makes it easier for us to help you out ;)

    Just upload the example and post it here. Then I'll check it for you.

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