Using Family to choose: How to check if an object exists?

This forum is currently in read-only mode.
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • I have a sprite which has a private variable that functions like UID (although not exactly the same purpose as UID), and I regularly use For Each Object (ordered) to loop through the instances of this sprite using this private variable. Instances of this sprite regularly get destroyed and created throughout the course of the game, and the private variable is unique for each instance upon creation of the instance.

    For any given sprite instance with a given private variable, I want to pick another sprite instance (using Families, since this sprite is in a Family) that has the next highest (or lowest) value of this private variable. And I can't assume that the next highest or lowest is just +1 or -1 away, since the sprite instances with these values may have been destroyed.

    In short, how do you check if a sprite you are picking using Families exists or not? I need to know this, so that if it doesn't exist, I can keep searching for the next one.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Why not just keep the next and previous values +1 and -1 away. When you destroy an object pick all the objects with greater values than the one being destroyed and subtract 1 from each. That will creating gaps.

  • Well, it won't be picked if it doesn't exist

    There is a "for each object ordered" where you could loop through them in order of the private variable

    If for whatever reason that won't work in a subevent of a "for each object" loop

    -family name is equal to (the number you're checking against)

    Then it will loop through each objectr but only go into those actions if the object also contains. The correct value

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