family vs instance woes

  • I am having a slight non-understanding here, i have members of a family, those members have their own variables, but those variables can't be used when using those members via spawned from a family, not that i can see. For instance, i have 6 different enemies, all with different health amounts, but all have a local health variable, but when i use them in a family, unless i give the family a health variable, i can't do damage to them because i can't call the health of the enemy that was spawned from the family.

    So, for now, i have if "bullet" collides with family unit "enemies" then do action of subtracting X amount from health, this is only possible if i have a variable called "health" on the family unit, but there is a "myhealth" on the individual enemy.

    Now, all i know of is to get to this outside of the family unit you can reach it via

    CyborgMulti.myhealth if your seeing it as a spawned CyborgMulti, so do i have to have individual events per every enemy to state on collision of "fire" against every enemy type, to then subtract said life? I have 4 different types of ammo right now, all 4 do different types of damage amounts, I just want to use a family unit hitting family unit and based on the object fired, do x damage to said family unit object, and have that object die based on its personal life amount, this so far does not seem possible in family structures.

    What am I missing? I have totally read through all of the docs on Family structures, i use them for grouping my enemies, etc, but it seems odd i can't get to or point to local instance variables, if they all have a "damage" amount for the weapons, and a local "life" amount, why can't the local "damage" amount be used against the local "life" amount instead of the family instance variable? they simply don't seem to transverse up the tree in C3

  • So you have "myhealth" variable defined on each of the 6 enemies sprites, and "health" variable defined on the family. Is this correct?

    If you have "health" variable on the family, why do you keep "myhealth"?? Just remove it from all family members and only use "health" in all events.

  • If all of the enemies have the same Instance variable names with the same intentions then use family variables. You can still set them separately. Family variable are the same as instance variables, they just make building your logic go a little faster and keeps the event sheets clean.

    There should not be any difference in how you call them. The only difference is how you can call events and set actions, it should not change how you reference them with the syntax either.

  • I only put the "health" on the family because there is no way to get to the "myhealth" on the family member, but that means all family members have the same "health" value, its global to the family and not independent to the family member.

    Example of what i expect to get to and can't:

    In your normal life, you have a family, that family has family members, such as mom, dad, brother, sister, each of these people have different ages, mom = 25, dad = 32, brother = 6, sister = 16, this is the local member variables to the family members age value.

    Now, when you add them all to a family unit, called WoodFamily, you can't add to mom value of age by calling WoodFamily.mom for instance, you can only get to the object of WoodFamily but you can't get to the WoodFamily members local instance variables from calling the family itself.

    If you create a family, add family members, make all the members before adding to the family have an instance value of the same name, when you use the family if you try to set or get that value, you simply can't, not by calling the family group, they have no method that i can see, that retrieves local family unit variables. And you can't create a family instance variable calling it the same as a family member instance variable, for example, trying to call by reference vs by value, i want to see this as inheritance in the engine, the family members only inherit from the family constsruct, the container can't get to the local instance variables, they are private to the family member and not available upwards.

  • I only put the "health" on the family because there is no way to get to the "myhealth" on the family member, but that means all family members have the same "health" value, its global to the family and not independent to the family member.

    That is incorrect.

    All family members will share the variable name, however each value is separate to each instance.

    Example:

    Family members: Mom, Dad, Son

    Family Variable: "Health" = 0

    In the properties menu of:

    Mom > Instance Variables > Heatlth = 90 ; Dad = 100 ; Son = 60

    Event: Family gets hit by a brick; Action: subtract 20 from health

    Which ever member is hit will lose 20 health relative to there own health

    Lets say Dad and Son gets hit, Dad now has 80 health and Son has 40.

    To get the Son's health simply request son.health

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Woh... i think i see.. ok, i originally had "health" on each enemy, when i tried to add that to the family since i couldn't touch the variable by calling Family.health, it told me that name was already taken, so then i removed it from all my enemies, put it on the family with a value then i could find and see Family.health, then all the members got that value, so looking at it right now, i then tried to change one of the family members value of that variable, thinking it would just copy to all the other members, it didn't, it kept the new value on the family member, of that single enemy.

    Now all i had to do, once creating the family variable was to update each family member with the value i wanted on that variable, how cryptic.. thanks for pointing this out sideways, my problem was the fact i had a local instance variable of Health on every member, then added them all to the family group, and tried to access that value, but couldn't at the family level, now i can.

    Man that just solved another headache!

    Thanks!

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