How to check if an object is in a family?

0 favourites
  • 5 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • So I have 2 families.

    The first is simply called "PlayerFamily", and encompasses everything in the game that is a "player", in other words objects that move, jump, attack, etc.

    The second is called "MountFamily". Every object in "MountFamily" is also a member of "PlayerFamily". Mounts are differentiated because they are players that can be ridden (horse, boar, dragon, etc).

    Generally I pick my objects via the "PlayerFamily", but what's the best way to check if an object in "PlayerFamily" is also in "MountFamily"?

  • <removed wrong awnser>

    edit --

    With the object picked, Compare picked count of the family selected and check if it's greather than 0

    Like

    if (FamilyA.pickedCount > 0)

    ->Object from Family A

    else if (FamilyB.pickedCount > 0 )

    ->Object from Family B

    Else:

    ->Object is not from family A or B

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • relixes I don't think what you suggested will work. Object, FamilyA and FamilyB are picked independently, if you pick one Object instance, FamilyA.pickedCount and FamilyB.pickedCount will still return the total number of instances.

    jwilkins I think the only way is to add an instance variable "isMount" to FamilyPlayer. Set it to true for all objects which are members of Mount family.

  • Thanks for the suggestions. I actually found a way that, while an elegant solution for me, might not be the best for others, but I figured I'd document it here.

    The short of it is that I am already heavily utilizing functions in my game (because you always should), so the PlayerFamily picks the appropriate MountFamily in this case, then passes that MountFamily objects UID to a function that identifies the MountFamily by its UID.

    However this function instead picks the MountFamily AS a PlayerFamily (remember, all Mounts are Players, but not all Players are Mounts) giving me access to all of the PlayerFamily functionality I already have setup.

    It would maybe be a little cumbersome on its own, but this baton pass approach easily fits into my heavy use of functions already, so it worked very naturally for my project.

  • I usually do it with one condition. Pick the relaxant instance and then the following will run if they are in the mountfamily. It may be more or less what you ended up doing. I didn’t read too carefully.

    Mountfamily: pick by uid playerfamily.uid

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