Destroy/Pick multiple instances

Get help using Construct 2

Post » Wed Jul 04, 2012 7:05 pm

Hello everybody,

I can't really understand how picking is working:

E.g. I clicked on the series of instances and saved their's UID's in the array. Than I want to destroy all that saved instances. I tried to use for each loop, but it picks & destroys only the last clicked object.

Why is "picking an instance" a condition? For me it sounds more like an action.

Please help.
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Wed Jul 04, 2012 8:13 pm

Picking an instance is a condition because you pick which instance you want to perform actions on. That makes sense, doesn't it?

Anyway, here's a quick example of picking an object in an array based on UID:
ArrayPicking.capx (r97)
Nimtrix2012-07-04 20:13:32
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Jul 04, 2012 8:25 pm

because action works on what is picked in a condition.

you should do something like

[code]Array: foreach X element
Sprite: pick by UID Array.CurValue
   -> Sprite: destroy[/code]
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Jul 04, 2012 11:30 pm

Thank you guys for the fast replies, but that's not exactly what I described above. I have to pick & delete multiple instances saved in the array at once. I attached capx, where I tried to do it.

https://www.dropbox.com/s/raye8ltumdis5eo/destoyMultiple.capx

It works like this:
- you click on cards
- every clicked card is saved in the array (UID)
- if array length = 4 this 4 selected cards should be deleted at once

In my example for each loop doesn't seem to work (loopindex is always 0)
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Thu Jul 05, 2012 3:37 am

destroyCards.capx

The main issue was to set the Array size to (0,1,1) not (0,0,0).
Because, if it's (0,0,0), your Array has no dimension and the push function doesn't "know" if you need to push a single element, a row or a 2D plane.

It's how I understand it.Yann2012-07-05 03:37:46
Last edited by Yann on Sun Sep 14, 2014 9:10 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Thu Jul 05, 2012 8:50 am

Thanks man - works perfectly now.
B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Thu Jul 05, 2012 4:41 pm

But something seems to be wrong with the loopindex. I just tried to trace iteration on an array with a straight forward setup and it throws zeros all the time

https://www.dropbox.com/s/brdtxrhxsstq4ge/loopindex.capx

B
42
S
11
G
4
Posts: 505
Reputation: 7,267

Post » Thu Jul 05, 2012 5:32 pm

Hmm, manual says loopindex returns "Current (top-level) loop index". My guess is it returns the Z index for each X you go through, it works fine if you use "Array.CurX" instead of "loopindex".
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Thu Jul 05, 2012 7:29 pm

yes, it's Array.CurX
B
42
S
11
G
4
Posts: 505
Reputation: 7,267


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests