random object selection

Get help using Construct 2

Post » Wed Dec 28, 2011 5:17 am

I am looking for my game to randomly select 3 out of 20 objects and display them on the screen. Then I would like the three objects to randomly rotate on the screen after about five seconds. what is the best way at going about this. I have tried system->on start of layout-> set layer random(0,19) three times, but what i run into is the system will sometimes randomly select the same layer twice, or even three times. is there a better way?
B
6
S
1
G
1
Posts: 52
Reputation: 829

Post » Wed Dec 28, 2011 5:44 am

Are they all different objects, or is it 20 instances of the same object?
If its all the same object you can do a loop, or repeat 3 times using pick a random instance under sprite actions. However that may pick the same instance more than once. To get around that you'll have to compare a private variable, but on the bright side you can use that variable to tell the system that that particular sprite was picked.
There's a function object you can use for the off chance one instance gets picked more than once... third party.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Wed Dec 28, 2011 6:03 am

i recommend that you make 20 instances of the same object. then you can use "objectcount" to create a loop. if objectcount returns less than 3, repeat random picking. if objectcount returns three, stop.
B
29
S
5
G
6
Posts: 58
Reputation: 5,121

Post » Wed Dec 28, 2011 7:56 am

Hello,

Thanks for your feedback!! I actually want to use twenty different objects. Any suggestions for that?

Thanks in advance
B
6
S
1
G
1
Posts: 52
Reputation: 829

Post » Wed Dec 28, 2011 10:19 am

Just use the same object and put the image representing them in different animation frame.
On start of frame set the frame to whatever you want
and don't forget to set the animation speed to 0. You can access it in the property panel when you are in edit mode.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 19 guests