how do I pick multiple instances at a time

0 favourites
  • 11 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • I`m noob to C2,and I met "picking" problems several times.

    Here is my case, I wanted to pick 4 instance at one time and make them visible.

    Here is how I did it by picking IID

    <img src="" border="0" />

    apparently, it doesn`t work the way that I want, how can achieve it?

  • Are these the only 4 instances you have, or do you have more?

  • Yes,I do have more instances than these 4

  • Do you want to pick these 4 instances at random, or by the desired UID? If you want to pick them by UID, store the UID's in an Array.


    System Repeat 4
    Pick Random (Instance) TileBackground3 | Set Visible


    System Repeat 4
    (Instance) TileBackground3 Pick instance with (UID) Array.At(loopindex) | Set Visible
  • If you are OK with just the first 4 instances, you can do for each and when the loop index reaches <= 4 break from the loop. It would also have the advantage of stopping the loop itself if you happen to have less than 4.

  • labithiotis

    I think the second case is what I want. Could u please explain me more how I can store the UIDs of the instances that I want in an array ? Thanks

  • theubie

    can I always pick the "first 4" from the same instance pool by using "pick by UID"? and remove picked from the instance pool, untill there is less than 4 left in the instance pool? since UID is unique for every single object in the level, how can I pick the "first 4"?


  • Make an Array with X:0 Y:1 Z:1

    On [b]Instance[/b] Created | Array Push Back [b]Instance.UID[/b] on X Axis  

    or if your destroying/adding your instances a lot you can do this before you event.

    Array Clear
    Pick all [b]Instance[/b] | Array Push Back [b]Instance.UID[/b] on X Axis 

    That way your'll always have an uptodate Array list

  • Try Construct 3

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

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

    The for each iterates through the objects based on their ID (UID is 0 based for all objects, starting at 0 from the first object placed), so if you use for each it's going to loop through them in order.

    capx (R119)

    You can make this further work with your setup by adding a condition to the for each event of sprite -> is visible = false, which means it will only loop through those you haven't shown yet.

    Edit: Fixed URL.

  • labithiotis

    I think I`m getting there by doing like you said

    <img src="" border="0" />

    now the only problem is there is only 1 instance appears, and the array width stays at 1 in log. how can I fix it?

  • theubie

    a BIG THANK YOU to you my friend, after tried your way it finally works. thank you!!

    theubie & labithiotis

    I think both methods "loop each"and "add to array" works to pick the first 4 instance in my case.

    thanks a lot guys !

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