How could I select random instances among a group

Get help using Construct 2

Post » Mon Jul 25, 2016 9:31 am

Hello, here is my problem,
I have a couple of purple sprite in my level
When I touch one of those purple sprite with my character their opacity become 50 (On collision-> set opacity to 50)
I would like to know how I could select randomly a purple sprite among those I have already touched
I know the event "Pick nth instance" but It pick a precise IID instance
I know also know the event "Pick random instance" but it allow me to pick one purple sprite among all instances, and I want to pick one among the purple sprites that I have already touched -> Is there a simple way to do that ?
B
13
S
3
Posts: 32
Reputation: 847

Post » Mon Jul 25, 2016 10:29 am

Hi,
You have to add boolean variable (for example, named "collision") in instance variables of the sprite and edit event [ON COLLISION -> SET OPACITY TO 50 AND SET collision TO TRUE]

Then use the system event, "PICK RANDOM INSTANCE" but add this event with this : "SPRITE IS collision" (don"t forget to invert it with right click -> Invert)...
B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Post » Mon Jul 25, 2016 11:07 am

Thank you Saad Swad for the help, I succeeded what I wanted to do thanks to you.
I did as you asked and add some stuff for fun :

Event : when character on collision with purple sprite =>Action : set opacity of purple sprite to 50, set "Collision" (instance variable of purple sprite) to 1.

Event : Every 1.0 seconds,"Collision"(instance variable of purple sprite)=1, Pick a random purple sprite instance => Action : Apply Physics Force (0,500) at image point 0.

Is there a way to join the project capx or images in the Forum, then this could help more other people ?
B
13
S
3
Posts: 32
Reputation: 847

Post » Mon Jul 25, 2016 11:53 am

Upload your image on server or drive (like dropbox (recomanded), googledrive...) and use this code in your post :
Code: Select all
[img=URL_LINK][/img]


Or simply post url link to your .capx (updated on dropbox for example...)
B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Post » Tue Jul 26, 2016 7:16 am

Super, I will post the link soon, thank you Saad Swad :)
B
13
S
3
Posts: 32
Reputation: 847

Post » Tue Jul 26, 2016 9:24 am

here is the link to access the construct2 (capx) file I was talking about :

https://www.dropbox.com/s/vrqcehkejm5ix ... .capx?dl=0

Please tell me if you can't access it, hope it will help you
B
13
S
3
Posts: 32
Reputation: 847

Post » Tue Jul 26, 2016 9:27 am

Note : you can move the red sprite with the arrow keys
B
13
S
3
Posts: 32
Reputation: 847

Post » Tue Jul 26, 2016 10:33 am

Perfect !
B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Post » Tue Jul 26, 2016 11:17 am

Super, Thanks !
B
13
S
3
Posts: 32
Reputation: 847


Return to How do I....?

Who is online

Users browsing this forum: John Cutter and 7 guests

cron