How do I Mirror Keys Between 2 Dictionary Instances

0 favourites
  • 5 posts
From the Asset Store
Sync animations, animation frames, mirror state, sounds and anything else using these methods.
  • I'm having a little trouble with this one.

    So I have a dictionary object. At runtime I create two separate instances of this object. Each instance is given an identical set of keys. One is intended to store some default values so that I can restore the other instances values to an original state periodically.

    However, I also want to skip a key in the process. What I'm currently calling the "alias" key, which stores a little name of the instance to help differentiate between the two instances.

    To make this a little easier (or so I thought), I placed this dictionary object in two families: "dict1" and "dict2".

    Then, on a function, I pick each instance through the two families.

    dict1 - Key "alias" = "temp"

    dict2 - Key "alias" = "default"

    Now, these two instances and only these two should be picked.

    Then, in a sub-event I use a "for each key" condition on the "dict1" family.

    And in another sub-event I invert the following condition.

    dict1 - Current key = "alias"

    Now in the actions I do:

    dict1 - Set key dict1.CurrentKey to value dict2.Get(dict1.CurrentKey)

    I thought that this would loop through each key and match the value unless the current-key matched the key that I didn't want to restore. In this case the "alias" key.

    However, currently it's not skipping that key.

    Any help would be greatly appreciated. I may just be misunderstanding something simple. If necessary I can provide an example .capx

  • Here is an example of how to copy keys from one dictionary to another.

    There are 3 keys:

    1 = A

    2 = B

    3 = C

    Keyboard:

    You can copy single keys with 1-3

    And all keys on 4.

    I haven't added any exceptions but shouldn't be hard to add them in the Copy all keys with some conditions I think. Anyway at least that's a way you could do It.

    (Use the debugger to see it)

  • Ah hehe, that does... some of what I need. But I'm not sure I can adapt it for my all of my needs. Importantly, I need to mirror the values of keys between two instances of the same object. And, the keys can't be numbered unfortunately (sneaky you). Well, they could but it would get confusing as I would have to place the key name in the value of the key or an index; then use tokens and such to get a "key" name, index, or value depending on where I put each.

    However, excluding one key from this mirroring process is my problem, not the basic mirroring of the values.

    In order to differentiate between the two instances of the object, I need to keep one key's value separate. This is the "alias" key. In my post I mention that the "alias" key of one instance is set to "temp" and the other is set to "default". This is the only key that I don't want to mirror.

    I thought that the problem might exist with how the "for each key" condition on a dictionary object works. It's not impossible to just roll my own, so to speak, but since dictionary keys aren't indexed by default, I would have to do that myself. Which would get a little messy and I consider that route something of a last resort.

    Heh, I'm never quite sure if I'm going in the right direction, but can anyway see why I'm placing the object in two different families? I've done similar when it comes to managing collisions between instances of the same object and I seemed to have similar needs in this situation.

    Again, if anyone is having trouble understanding my first post's explanation of what I'm trying to do, then I can make an example .capx.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [quote:4f4pops4]However, excluding one key from this mirroring process is my problem, not the basic mirroring of the values.

    Not sure if I understand what you mean, but there is no difference in using numbers as keys or something else.

    When you press 4 to copy all keys in this example, it will exclude the first key:

    If that is not what you mean then im not sure I understand what you want.

    [quote:4f4pops4]In order to differentiate between the two instances of the object, I need to keep one key's value separate. This is the "alias" key. In my post I mention that the "alias" key of one instance is set to "temp" and the other is set to "default". This is the only key that I don't want to mirror.

    But you can just use two different objects and in the start of layout, make it copy all keys, as in the screenshot, and just remove all exclusions. Then you make another one, that copy keys using exclusions. Then you don't need to worry about families, identification key etc.

  • Hmm, for some reason I thought that dictionary keys weren't indexed. Your method looks like it will work just fine.

    Thanks for your help, this one had me stumped.

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