[SOLVED]Comparing variables of different family members...?

0 favourites
  • 10 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Hello World,

    Please check the capx below. As you can see I have 2 families, one with monsters and one with ammo. And each member of each family has different properties defined in instance variables for each object ammo/monster type(the shape it is, circle, square, etc.), what color it has, and if it has any signs on it.

    Then you will see I have one event AllAmmo on collision with AllMonsters.

    I would like someone to please make the code there to show me how to do the following:

    • when an ammo colides with a monster pick only the 2 members of each family that have just collided(as I understand C2 does this automatically because it's a triggered event and because of how families work?)
    • then(on that collision) compare the instance variables of just those 2 members that have just colided to see if they are equal ammotype=monstertype, color=color, sign=sign(and remember these variables are on each object itself, not on the family)
    • if all variables are equal call function x, else(if any of them is not equal) call function y

    Capx link: https://www.dropbox.com/s/juvesdjguknqs ... .capx?dl=0

    If you have any questions let me know. Thank you.

  • Put the instance variables on the Family, not the Sprites.

  • I can't do that blackhornet I have hundreds of objects and for each of them those 3 variables differ. So first of all it would take forever to do and second of all I don't even see how that would help.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • second of all I don't even see how that would help.

    It would help with comparing the variables, which was your question, right?

    If the family doesn't have variables, there is nothing to compare..

  • Give it a try. You misunderstand how Family instance variables work.

  • I misspoke there LittleStain what I meant to say was "I don't even see how that would work."

    Could you guys please use that capx, modify it to show me what you are talking about? Because I don't think we're on the same page...

  • Ok, that's what I suspected you might be talking about, but I don't really understand how that works blackhornet .

    So when I do that it's gonna pick the value of the instance variable from the object that just colided then automatically copy that value into the instance variable of the family(if they have the same name?) and then compare variables of the families which now have those copied values to see if they match?

    Is that what's going on, or am I getting it wrong, how exactly does that work?

    LE: And then I'm gonna right click on those 3 conditions, add else, and that "else" is gonna mean "if eighter of those 3 is not equal then do this"?

  • You are overthinking this. A Family is just a way to group objects. There is no separate storage, those instance variables are now part of each of those objects, that's why you can set them, even though you are clicking on the base object in the GUI (GreenSquareAmmo, for instance. Clicking on that object shows the instance variable are already there, the same as that object's own instance variables).

    LE: yes, if any of those 3 are not a match, Else will run.

  • Well, that's me, I always overthink things. Ok, thanks for the help and explanations blackhornet , time to get back to work I guess.

    Sadly it seems that now I have to delete the variables for all the objects(and I have hundreds of them...) then add them to the family, then go and edit them again for each object.... It's gonna take forever, sigh...

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