How do I make my dictionary recognize global variables?

Get help using Construct 2

Post » Sun Oct 30, 2016 5:22 pm

I got a json file with 720 values that I load into my dictionary.
Image

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

so l1&l2&l3&l4 should be abcd

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

Anyone know how to get the values that the global variables for l1-l6 have into the dictionary ? :roll:
B
5
Posts: 10
Reputation: 247

Post » Mon Oct 31, 2016 3:54 am

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?
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Oct 31, 2016 10:37 am

@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).
B
5
Posts: 10
Reputation: 247

Post » Mon Oct 31, 2016 12:38 pm

don't use variables...use array

abc.capx
Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896

Post » Mon Oct 31, 2016 5:02 pm

@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?
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Oct 31, 2016 8:45 pm

Message: boulerzzz can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
@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: http://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.
B
5
Posts: 10
Reputation: 247

Post » Mon Oct 31, 2016 11:33 pm

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:
Code: Select all
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

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.
https://dl.dropboxusercontent.com/u/542 ... /dict.capx
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, Bootfit, Exabot [Bot], Huemerson, unicornspitfire, Yahoo [Bot] and 1 guest