Create a Family object if the objectTypeName matches a Dictionary key

0 favourites
  • 5 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • Hi!

    I seem to be a bit stuck with this:

    I have a Dictionary object that holds all kinds of keys for the objects the player has collected in the game. Some of those keys are not relevant for the main inventory screen where the player can pick objects for use.

    I have a family that contains only the objects that should be created in that main inventory.

    Is it possible to loop through my Dictionary and only create an object if it's part of this family? In other words I want to ignore all keys that do not match objectTypeNames in this family, but as soon as there is a match, I want to create that object from the family.

    Is this possible in Construct?


  • So the dictionary may contain keys like "chicken", "banana" and "apple". But you only want to create objects from the family "Fruits", and avoid creating the chicken sprite?

    I'm afraid the only option is to make a list of all objects in the family. It may be a simple text variable with a comma-separated object names. Then you can use find() expression to check if the dictionary key is in this list.

  • Yes you got that right!

    I'm trying to use families as much as possible and try to avoid the need for "hardcoding" values. If I need to type in a bunch of strings every time I add a new object type in my game, the likelihood of bugs increases.

    Thanks for confirming that this is not really possible at the moment. It would be really useful if we could access objectTypeNames in a family even before those objects have been created.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well, you can try creating an object with dictionary key name, then checking if it belongs to the family. If not - delete it immediately.

    This may not be a good solution if you have lots of keys in the dictionary, which may match different object names.

  • Yes I thought of that possibility as well. It's certainly a possible workaround in this situation. But somehow it feels a bit ugly to create an object just to delete it immediately. That's why it would be nice to have a way of accessing all objectTypeNames of a family.

    Anyway thanks for your input, I appreciate it!

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