How do I make my dictionary recognize global variables?

0 favourites
  • 7 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I got a json file with 720 values that I load into my dictionary.

    Problem is: I would like the dictionary to recognize the values that l1,l2,l3,l4,l5 and l6 are.

    so l1&l2&l3&l4 should be abcd

    Never used dictionaries or json files before so I dont know if this even is possible

    Anyone know how to get the values that the global variables for l1-l6 have into the dictionary ?

  • The keys are just text so maybe you could just set the key's to be like "abcd" to begin with?

    I mean you could convert the text "l1&l2&l3&l4" to "abcd" using the replace() expression, or even the reverse. Would that help?

  • R0J0hound The thing is the values of l1-l6 changes every now and then, which generates new combinations. The dictionary must automatically be updated with the new combinations.

    I still dont really understand why the dictionary recognizes the values of global variables l1-l6 when I add "l1&l2&l3&l4&l5&l6" into the dictionary manually but when I load from a json file it remains as just "l1&l2&l3&l4&l5&l6"

    It would work if I add all 720 combinations manually into the dictionary but that would take forever! (not really but almost).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • don't use variables...use array

    abc.capx

  • boulerzzz

    It's different, when you type it in C2 it's a expression and when you put it in your json data it's text, which is the same as if you put your expression in quotes. So basically json is just data and not expressions.

    I guess I'm not understanding the purpose of the dictionary and how you want to use it, since this seems overly complicated.

    My guess is you want to lookup if "abcd" is in the dictionary so you'd need to convert that to " l1&l2&l3&l4" first before looking. Surely there's a simpler approach?

  • R0J0hound I should have explained my problem better. So I've got dictionaries that contain all 3 letter, 4 letter, 5 letter and 6 letter words in the English language. Now I wanted to check how many of these words that can be created with the 6 characters the computer randomly generates.

    For example if I have these letters: [E,c,r,s,u,i] I could spell "cruise" or "rise".

    Originally I made a loop that generated all possible combinations. I then checked how many matches this list would get in each dictionary. (obviously removing letters from right when checking the dictionaries with words fewer than 6 letters.)

    The problem with that solution was that it generated combinations like eeeeec,eeeeer and so on. Basically it used every character more than once so I ended up with about 40k combinations. Naturally that resulted in too many matches because the player can use every character only once.

    I figured out that there are 720 combinations if you use every letter only once.

    If you have these 6 letters. [abcdef] you can create 720 6 character combinations

    (ab) (ba) then add third character

    [(cab) (acb) (ABC)] [(cba) (bca) (bac)] then add 4th character

    (dcab) (cdab) (cadb) (cabd).... The last line would be 720 combinations. I wanted to take these combinations and replace the characters with whatever letters the computer gave me and check how many matches that would give me in the dictionaries with English words.

    Then when the letters change it would automatically check how many words that can be created with the new set of letters.

    korbaach I will look at the capx and see what I can make of it when I get home tommorow or later this week. I only got access to my cellphone now so I can't open construct for a while.

    I hope you understand what I am trying to do. I'm not very used to producing text in English since its not my first or even second language but I tried to the best of my ability.

    Thank you for the help!

    Edit: textmechanic.com/text-tools/comb ... generator/ found this on internet while browsing! This is what I'm talking about. Generate a dictionary with all combinations of 6 characters by using every character only once.

  • Well, assuming you have all the words in a dictionary you should be able see if any word is in the dictionary with a simple "has key" condition.

    You then can roughly find all six letter words with:

    var letters="abcdef"
    var count= len(letters)
    for l1=0 to count-1
      for l2=0 to count-1
      if l2 <> l1
        for l3=0 to count-1
        if l3 <> l1
        if l3 <> l2
          for l4=0 to count-1
          if l4 <> l1
          if l4 <> l2
          if l4 <> l3
            for l5=0 to count-1
            if l5 <> l1
            if l5 <> l2
            if l5 <> l3
            if l5 <> l4
              for l6=0 to count-1
              if l6 <> l1
              if l6 <> l2
              if l6 <> l3
              if l6 <> l4
              if l6 <> l5
                var word= mid(letters,l1,1)&mid(letters,l2,1)&mid(letters,l3,1)&mid(letters,l4,1)&mid(letters,l5,1)&mid(letters,l6,1)
                if dictionary has key: word
                  add word to wordlist[/code:2i99mh1e]
    Different length words can be done similarly.
    
    Now that's an easy to understand solution it just can be tedious.  There are ways to simplify it quite a lot, and here's an example using a recursive function to make that much more compact.  I probably won't be able to explain it well enough to be helpful.
    [url=https://dl.dropboxusercontent.com/u/5426011/examples35/dict.capx]https://dl.dropboxusercontent.com/u/542 ... /dict.capx[/url]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)