Adding condition to random picking

Get help using Construct 2

Post » Sat Sep 20, 2014 2:16 pm

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
You do not have the required permissions to view the files attached to this post.
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Sat Sep 20, 2014 2:31 pm

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Sep 20, 2014 3:07 pm

@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.
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Sat Sep 20, 2014 3:11 pm

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.
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Sat Sep 20, 2014 3:17 pm

Something like this?
You do not have the required permissions to view the files attached to this post.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Sep 20, 2014 4:06 pm

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?
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Sat Sep 20, 2014 4:27 pm

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..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Sep 20, 2014 5:51 pm

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!
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 12 guests