How do I choose which family member object is created?

0 favourites
  • 6 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Is there way to have a comparison of a family instance variable set as condition in the create event of a member of a different family somehow?

    ...would like to reduce 7 almost identical code blocks into 1 more generic one.

    crude example:

    each sprite2 in sprite2family has a family instance variable called sprite2family.familyinstancevariable which was assigned a certain sprite1.uid

    can´t find a way to do something like this:

    on left mouse button clicked on sprite1family -> create sprite2family.familyinstancevariable=sprite1family.uid[/code:2cuzyk0g]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I not sure I understood your explanation..

    So you have 2 families:

    ColorsFamily (containing sprites Red, Yellow, Green)

    FruitsFamily (containing sprite Lemon, Cherry, Kiwi)

    And when Yellow sprite is clicked, you want to create Lemon, is this correct? And do it in 1 event, not in 3?

    When you use Create/Spawn event with family, a family member is chosen at random.

    So no, unfortunately you can't select which member of the FruitsFamily will be created.

  • thanks a lot dop2000 for the answer, this limitation seems a bit odd but I guess I can live with it

  • No worries.

    I have the same problem in my game. I needed to create a specific sprite from the family of 10+ sprites and then assign it a bunch of variables, set lots of parameters for different behaviors etc.

    So I did this:

    Variable newUID=0
    if <some condition> Create Cherry
                        newUID = Cherry.uid
    else if <some condition> Create Kiwi
                        newUID = Kiwi.uid
    else if <some condition> Create Lemon
                        newUID = Lemon.uid
    
    Pick FruitsFamily by unique id=newUID
      FruitsFamily -> set instanceVariable1
      FruitsFamily -> set instanceVariable2
      FruitsFamily -> set instanceVariable3
      FruitsFamily -> set Bullet speed
      FruitsFamily -> set Bullet angle
      FruitsFamily -> set Fade duration 
      FruitsFamily -> etc.
      FruitsFamily -> etc.
    [/code:2a1epred]
  • It would greatly help if we could state which objects we want to create dynamically, instead of picking them from a box, like in any other programming framework.

  • When you click on Sprite1F send the UID through a function as a param.

    In the function create Sprite2F where Sprite2F.var = param 0.

    Or outside of a function I think you can use system condition 'Pick by evaluate' easily enough.

    Maybe that's what you want, OP is a little confusing.

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