How do I pick a random object from the family?

0 favourites
  • 7 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello,

    I have a family consisting of 10 different fruits. None of these fruits are yet created on the layout. Is there a way in which I can pick a random fruit from that family and create it on the layout?

    I cannot use the pick system condition as none of the members of the family are created yet.

    To be precise what I am trying to achieve is:

    I have 15 placeholders on the layout (1 object 15 instances). There is 1 fruit family (consisting of 10 different fruits). I want to randomly pick any one of the fruit from the family and pin it randomly on any of the 15 placeholder (upon doing this, the placeholder that already has a fruit pinned should not be picked again).

    Any suggestions or a way to achieve this?

    Tagged:

  • It could be better to make one object with different animations instead of 10 objects. You can use the Is playing condition if you want each of them to have different events and actions. If you do this you can set the animation to str(round(random(1,10))).

    For Each Placeholder -> Spawn another object (fruit)

    Also, do you want to use pin to just set position or is there another reason?

  • Following example has 2 different way to create random object: dropbox.com/s/1ng5la2xx3yjyvr/summon_random.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It could be better to make one object with different animations instead of 10 objects. You can use the Is playing condition if you want each of them to have different events and actions. If you do this you can set the animation to str(round(random(1,10))).

    For Each Placeholder -> Spawn another object (fruit)

    Also, do you want to use pin to just set position or is there another reason?

    What happens when I have multiple instances of the same fruit? How can I uniquely identify them to trigger events or actions?

    I am using pin because I am trying out a vertical scrolling game. If the fruits are pinned to the placeholder, they will move along with it.

  • Following example has 2 different way to create random object: dropbox.com/s/1ng5la2xx3yjyvr/summon_random.capx

    Thank you for sharing this. However, I am unable to open it. Can you please take a snap and share?

  • You just need to click the download button. Since I am in mobile I can only share limited screen as follow:

  • Not sure if this will work but maybe you can pin them if they collide or overlap with the placeholder.

    You might be able to uniquely identify them using one of the pick instances conditions.

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