Adding condition to random picking

0 favourites
  • 8 posts
From the Asset Store
Kids Game
$49 USD
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • I would have expected you could select random instances based on a condition. but maybe it's not possible?

    I basically want to loop through all instances and Pick a Random Instance that wasn't picked before.

    Can anyone shed some light?

    I'm attaching a capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I haven't opened your capx, but it seems to me you should first pick all instances that conform to the condition and after that pick a random one..

  • LittleStain well the condition changes as the picking occurs.

    so I have 20 black boxes (my grid) and I want to place 10 blue boxes randomly on top of them.

    when I place a blue box on a black box I set an instance variable on the black box: Occupied to TRUE. When I continue to pick black boxes I am trying to exclude black boxes that are occupied.

  • sorry, I should first say that I am looping through each blue box to begin with. I'm placing each of them onto a random black box. I'm just trying not to overlap them.

  • Something like this?

  • oh.. I see what you mean about 'picking all'.. so use that as a way to figure out what's been used already..okay makes sense.. thanks!

    do you think this is the best way to do this?

  • I'm an "If it ain't broken, don't try to fix it" kinda guy..

    If you were to add more conditions it might be wise looking if using loops, repeats, functions and even arrays would be beneficial, but I like the simplicity of this and when looking at it I immediately see what it is for, all the other stuff can confuse me sometimes..

  • thanks LittleStain I agree... at first I made an array of x/y coordinates and was trying to sort the array randomly then picking random array elements and using those to place the blue boxes.. that all seemed way too hard which is why I switched to the random function.

    cool, thanks for the help!

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