Get the value of my dictionary

0 favourites
  • 4 posts
  • Hello everyone,

    I have some variables and values in a dictionary and I would like to compare the variable to an entry in an array.

    For exemple in my array I have an entry like "Item_Name1", then I want to get the value from my dictionary with a variable named "Item_Name1"

    I'm actually doing something like this:

    + MyDictionary: For each key

    ----+ MyDictionary: Key MyDictionary.CurrentKey = MyArray.At(Object.Line,0)

    -----> MyDictionary: Set text to MyDictionary.Get(MyDictionary.CurrentValue)

    Object.Line is supposed to give the current X value.

    The Y (0) is the entry I want to compare ("Item_Name1" for my exemple)

    Seems that it can't get the value because it returns "0"

    Any suggestion?

    Thanks!

  • It's always so hard to read these copypasted events. I'd rather see a screenshot of the events.

    But I think the issue might be this line

    MyDictionary.Get(MyDictionary.CurrentValue)
    

    You are trying to get a value from the array, it should be

    MyDictionary.Get(MyDictionary.CurrentKey)
    

    And you are already looping through anyway, the current value is already availabe with just

    MyDictionary.CurrentValue
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here is a screenshot, maybe it's easier to get where my problem is:

    I also tried something different. First I save my item name in a local variable, so it's exactly the same variable name recorded in my dictionary. Then I compare the variable's names to get the corresponding value (a number in this case)

    But even like this I can't get my value…

  • Ok I just get it. I was using the Dictionary in a totally wrong way.

    I used to add the instance variables directly in the dictionary proprieties so I didn't have any key in it. I did't created a Json file fist with all my keys and values.

    So here is what I was supposed to do first:

    + System: On start of layout

    -> AJAX: Request MyDictionaryFile.json (tag "Dico")

    -> System: Wait for previous actions to complete

    + AJAX: On "Dico" completed

    -> MyDictionary: Load from JSON string AJAX.LastData

    And now this works fine:

    -> Text: Set text to MyDictionary.Get(MyArray.At(Object.Line,0))

    Maybe it to should be noticed in the manual…

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