Need help with family object

0 favourites
  • 7 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hey

    I ran into a problem that i hope someone can help me with.

    I have a family called buildings, which contain different types of buildings.

    I would like to reduce one of the variable for all buildings, but i cant seem to get it to work.

    Lets say i wanted to reduce A by 10% for all buildings.

    How do you change it for all of them? i have tried to use pick all buildings, and for each building but doesnt seem to have any effect.

  • Is your variable in the family or in each building?

    You can use for each in this case but it's not necessary.

    the capx: buildings_capx

    use the letter "I" on the keyboard to see that the variable for each building is decremented by 1.

  • Hi Kaisirak

    They are familiy variables.

    I tried your building.capx and modified it so it matches my situation.

    Modified buildings

    if you press "1" it will just spawn a goblin at 100,100 and then subtract its cost from credit.

    which works fine.

    If you press "I" it will now just set cost of all buildings to 5. But when you press "1" it will correctly check for the new cost value, but it will still subtract 10 from the credit.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I see the problem.

    When you create a new instance, construct2 "picks" it, and since you assigned 10 as the default A value, it reduces your credit by 10. What "I" does is set A to 5 for all the instances that already exist.

    A simple solution to this problem would be using an array to store each type of building's cost.

    Here is the capx: modified_buildings

  • Its a bit weird, anyone that works with families must run into this problem at some point, if they ever want change a value in that family, before creating them?

    It would be nice with a create family object, where you could specify which object in the family you wanted to create. That way you would be able to do it, as far as i see.

    I can set the value if i use pick nth instance i want when assigning a new cost, but it doesnt work with the create object unfortunately.

    I think i might run into a lot of problem later on if i use an array like you did, and it will make the project really messy, with so many buildings array which i cant keep track off.

    Ill try to see if i can make a work around for it.

    But thanks for the help.

  • Well no actually, that's the point of the array, you won't make a mess precisely because you only need one X for each type of building instead of having an instance variable for each object you create and then having to decrease each of the existing objects' variable.

    What you don't seem to understand is that you can't change the default value assigned to a type of object, however what you can do is change the value you check when creating a new instance, which is what I do with the array. But nothing prevents you from using a variables in a player object, that would work just like the array.

    TL;DR : you can't change the default value, because it's a default value, arrays rule, I'm awesome

    Kaisirak out...

  • Yeah but each family can have X number of objects which have an variable called the same but with a different default value.

    If you make an instance of an object it should get the default values of its parent.

    So if:

    object A: I = 10

    object B: I = 15

    and are in the same family.

    so if you make an instance of object A as far as i know, it should inheritance its I value.

    So if you change object A I value, newly created children of that object should get that value as well.

    As far as i see it, its no different in construct 2, there is just not a function that allows you to specify what "family member" you want to create.

    But i might be wrong, but i cant see why there should be a problem in changing a parent object default value, just because its part of a family.

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