How do I spawn specific object from family

  • Hi,

    I'm working on a tactical game where you can choose several different characters for a team. I don't want to create a block of code for each character for every action, for instance, selecting the character with the mouse to put in your team.

    I tried to putting all of the characters into a family and giving them all a "name" variable. So I can click on a character from the family, then pick it based on the comparison of the name, and then spawn a new one over in the team queue.

    The pick seems to work correctly if I use "set text" or something to view the result, but when I spawn "characters", it just grabs a random one out of the group still. I looked through the forums and found someone said to "pick all" first. This didn't work. It didn't sound like the same problem, but I thought I would try it.

    Does anyone have any suggestions? Thank you for your time!

  • I think the only vanilla C2 solution is to spawn the specific object directly (not through the family), however the nickname plugin can spawn an object by name

  • I do not know if this could serve but read this section of the manual

    https:// /manual/ 130/ common- features

    remove space

  • Thanks for the help, I'll check into these suggestions later. If I can't find a good solution I may make a request to scirra to let us spawn objects by expression. I know I'm not the only person that would benefit from this.

    Thanks again!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi,

    I'm working on a tactical game where you can choose several different characters for a team. I don't want to create a block of code for each character for every action, for instance, selecting the character with the mouse to put in your team.

    I tried to putting all of the characters into a family and giving them all a "name" variable. So I can click on a character from the family, then pick it based on the comparison of the name, and then spawn a new one over in the team queue.

    The pick seems to work correctly if I use "set text" or something to view the result, but when I spawn "characters", it just grabs a random one out of the group still. I looked through the forums and found someone said to "pick all" first. This didn't work. It didn't sound like the same problem, but I thought I would try it.

    Does anyone have any suggestions? Thank you for your time!

    Use Animation Name, example:

    On click on character selection x

    if character selection x animation name = "fluffy"

    character creator set animation.name (which will be the sprite fluffy) and that's how you spawn and keep the characters name.

    or doesn't use direct value at all:

    make a persistent object x to store the animation.name

    on click on button x, get animation.name > sprite create and/or switch to persistentobject.x (its the animation value)

    Does this makes sense to you?

  • Thanks for the suggestion lwgames, I ended up using the nickname plugin which let's you create an instance of an object using an expression, so at selection I saved Characters.name to objectClicked then used Nickname to "create objectClicked". Works very well and reduces dupicate code. Thanks a lot Aphrodite for suggesting the plugin!

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