Pick random instance

Get help using Construct 2

Post » Fri Apr 06, 2012 4:37 am

I want the system to pick a random instance of ball (there are three balls by the way) and destroy it without harming the others, how? @Ashley?
B
20
S
4
G
4
Posts: 129
Reputation: 5,535

Post » Fri Apr 06, 2012 6:04 am

Just create a new condition or event System->Pick Random Instance.
http://www.scirra.com/manual/124/system-conditionsZephlon2012-04-06 06:05:03
B
25
S
8
G
8
Posts: 71
Reputation: 5,307

Post » Fri Apr 06, 2012 2:13 pm

Yes, @Zephlon, i did but when you type

SystempickrandomBallinstance        Ball Destroy

It destroys all of the Balls! I'm not sure how to fix this. I guess I should've beeen more specific...
B
20
S
4
G
4
Posts: 129
Reputation: 5,535

Post » Fri Apr 06, 2012 2:32 pm

can you provide your capx ?

Here's an example:
http://dl.dropbox.com/u/65731657/destroyrandom.capxWishy2012-04-06 14:39:18
B
22
S
11
G
9
Posts: 133
Reputation: 6,572

Post » Fri Apr 06, 2012 5:11 pm

If "Pick random instance" is the only condition you have, it will just keep picking instances and destroy them one after the other, so you'll probably need another condition i.e. "Trigger once while true".
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Fri Apr 06, 2012 9:23 pm

Don't worry, I figured it out (with your help of course)
B
20
S
4
G
4
Posts: 129
Reputation: 5,535

Post » Thu Feb 13, 2014 7:26 am

How did you get it to work? I'm trying something similar and it keeps selecting all the objects. I have...
> On created
> System Pick a random Object instance
    > Trigger Once > Object Set Opacity to 10

Doesn't work. I tried putting the Trigger Once everywhere, inside the parent condition any outside and all over the place to no avail.
B
6
S
2
Posts: 29
Reputation: 581

Post » Thu Feb 13, 2014 7:31 am

Trigger once while true has to be tied to something. What is making it run? An object being created? Well then, anytime an object is created, it will be destroyed, it's opacity will be set, etc.
Don't lose your work. Backup your game with Dropbox.
B
43
S
10
G
10
Posts: 1,106
Reputation: 9,147

Post » Thu Feb 13, 2014 7:36 am

Oh hey I figured it out too. I'll post my solution though for anyone that searches for this exact same issue:

1. create a global variable (gvar) you're going to count up

>Object on created > Add 1 to gvar

>System gvar >= total number of expected objects
-->System pick a random Object instance + Trigger Once > Object (destroy, or do whatever to it)

In my case it looks like this:

B
6
S
2
Posts: 29
Reputation: 581

Post » Thu Feb 13, 2014 7:37 am

@TiAm: Yeah that was exactly the issue. I should go to sleep, brain not working at full capacity :<
B
6
S
2
Posts: 29
Reputation: 581

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests