how do I pick multiple instances at a time

Get help using Construct 2

Post » Sat Feb 16, 2013 8:49 am

I`m noob to C2,and I met "picking" problems several times.
Here is my case, I wanted to pick 4 instance at one time and make them visible.
Here is how I did it by picking IID

apparently, it doesn`t work the way that I want, how can achieve it?
B
12
S
1
Posts: 7
Reputation: 1,141

Post » Sat Feb 16, 2013 9:15 am

Are these the only 4 instances you have, or do you have more?
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Sat Feb 16, 2013 9:18 am

Yes,I do have more instances than these 4
B
12
S
1
Posts: 7
Reputation: 1,141

Post » Sat Feb 16, 2013 10:41 am

Do you want to pick these 4 instances at random, or by the desired UID? If you want to pick them by UID, store the UID's in an Array.

Random:
[code]
System Repeat 4
Pick Random (Instance) TileBackground3 | Set Visible
[/code]

Fixed:
[code]
System Repeat 4
(Instance) TileBackground3 Pick instance with (UID) Array.At(loopindex) | Set Visible
[/code]
B
24
S
11
G
5
Posts: 140
Reputation: 5,004

Post » Sat Feb 16, 2013 11:47 am

If you are OK with just the first 4 instances, you can do for each and when the loop index reaches <= 4 break from the loop. It would also have the advantage of stopping the loop itself if you happen to have less than 4.
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Sat Feb 16, 2013 12:00 pm

@labithiotis

I think the second case is what I want. Could u please explain me more how I can store the UIDs of the instances that I want in an array ? Thanks
B
12
S
1
Posts: 7
Reputation: 1,141

Post » Sat Feb 16, 2013 12:22 pm

@theubie
can I always pick the "first 4" from the same instance pool by using "pick by UID"? and remove picked from the instance pool, untill there is less than 4 left in the instance pool? since UID is unique for every single object in the level, how can I pick the "first 4"?

thanks
B
12
S
1
Posts: 7
Reputation: 1,141

Post » Sat Feb 16, 2013 12:45 pm

Make an Array with X:0 Y:1 Z:1
[code]
On Instance Created | Array Push Back Instance.UID on X Axis
[/code]

or if your destroying/adding your instances a lot you can do this before you event.

[code]
Array Clear
Pick all Instance | Array Push Back Instance.UID on X Axis
[/code]

That way your'll always have an uptodate Array listlabithiotis2013-02-16 12:53:17
B
24
S
11
G
5
Posts: 140
Reputation: 5,004

Post » Sat Feb 16, 2013 8:21 pm

@zhxauo

The for each iterates through the objects based on their ID (UID is 0 based for all objects, starting at 0 from the first object placed), so if you use for each it's going to loop through them in order.

capx (R119)

You can make this further work with your setup by adding a condition to the for each event of sprite -> is visible = false, which means it will only loop through those you haven't shown yet.


Edit: Fixed URL.theubie2013-02-17 04:10:01
B
26
S
8
G
3
Posts: 210
Reputation: 5,973

Post » Sun Feb 17, 2013 2:37 am

@ labithiotis
I think I`m getting there by doing like you said

now the only problem is there is only 1 instance appears, and the array width stays at 1 in log. how can I fix it?
B
12
S
1
Posts: 7
Reputation: 1,141

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests