How do I create a given object from a family

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

    I would like to create a given object from a family based on a variable.

    However, the manual says : "[When creating an object] if a Family is chosen, a random object type from the family is picked, and an instance created for that."

    To be very clear, I defined a family instance variable "uniqueNumber" and gave every object in the family a different value for it in the properties. Now I would like to create an object from that family based on this variable.

    Is there any way to do that?

    Thanks a lot!

  • Do a search for the Nickname plugin. C2 doesn't support this natively.

  • Thanks a lot Looking into this plugin now.

    It looks like once again rexrainbow will come to help me.

  • I downloaded and tried the Nickname plugin, but I still don't see how it could help me select a given instance of a family based on a number variable.

    Sure, I can assign a nickname to each object, but I don't see how it makes it different in my case than just creating each different object.

    The problem is that the family's name needs to be a string : "one" instead of 1.

    In the latter case I would be able to call the nickname based on the number variable, but I don't see how to do that with the string.

    Am I missing something? Or is there any other way to achieve this?

  • Rable

    Try this sample capx

  • rexrainbow

    Thanks a lot! This is a very interesting plugin and the capx linked helped a lot in understanding it!

    It's still a bit mysterious for me at the moment but I can definitely see the potential. I'll see if I can manage to use it properly in my code.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • To keep you updated, I manage to do what I wanted. And if someone ever needs to do it, I'm going to explain how I did it.

    What I had was an array with 40 X entries and a number value in each of them. I wanted to create given object from a family based on this value. For this I created an family instance number variable and assigned a different value for each object in the family.

    But as blackhornet told us that doesn't work, as we can't create a given instance from a family based on a variable. The instance created will always be a random object type from the family.

    It was possible however using rexrainbow 's plugin Nickname. Instead of defining a number instance variable for each object type in the family, I added a family behavior Nickname, and entered a different string (A, B, C, D, ...) for each objet type in it.

    I then stock these values in the same array as previously but as strings.

    Then the below event just creates an instance from the family (placementTrumpet) which has the same Nickname than stocked into the array at curX.

    Exactly what I wanted to achieve, thanks a lot rexrainbow for the awesome plugin!

  • Rable

    Sets "Mode" to "SID" if you don't care the value of nickname ( you will not fill the nickname parameter manually ). Nickname will be filled automatically in this mode. See previous capx (Update rex_bnickname behavior first).

  • Oh, I wondered what SID was about. I will remember that for the next time.

    Thanks!

  • Rable

    "SID" is the id of object type which created by c2 engine, it is an unique value for each object type.

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