Destroy first of instances [SOLVED]

Get help using Construct 2

Post » Mon Aug 01, 2016 2:05 am

If i have objects that get created one by one, how do I get rid of the oldest instance (first) if there is more than 10. For example, imagine bubbles with numbers in them (1,2,3, ... 10). When bubble 11 gets created, 1 get's destroyed. When bubble 12 is created, bubble 2 get's destroyed and so on. Alternatively, the numbers could shift so it destroys bubble 1 each time.
Last edited by jook00 on Mon Aug 01, 2016 4:27 am, edited 1 time in total.
Check out my games on Google Play:

BEAST ATTACK (960,000+ downloads!)

ZOMBIE BASH (Android) (Launched Feb 17)

ZOMBIE BASH (iOS) (Launched March 17)
B
50
S
15
G
2
Posts: 427
Reputation: 5,164

Post » Mon Aug 01, 2016 3:07 am

https://www.scirra.com/manual/124/system-conditions
Pick Nth instance
Pick the instance at a given place in the internal list of picked objects. This is most useful used in sub-events to act on separate instances. For example, in a "Sprite collided with Sprite" event, Pick 0th instance and Pick 1st instance can be used to act on each instance involved in the collision separately.

If all objects are currently picked, this condition can also be used to pick an object by its index ID (IID). For more information, see common features.


After picking the 0th instance (oldest), you action (destroy) will then only apply to that instance.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Aug 01, 2016 3:16 am

I'll have to dig into this further, but after putting 0 as the instance, it's getting rid of the last object and not the first (oldest). I might be doing something wrong though.
Check out my games on Google Play:

BEAST ATTACK (960,000+ downloads!)

ZOMBIE BASH (Android) (Launched Feb 17)

ZOMBIE BASH (iOS) (Launched March 17)
B
50
S
15
G
2
Posts: 427
Reputation: 5,164

Post » Mon Aug 01, 2016 3:19 am

Whoops maybe I was backwards. If 0 is the newest, then Object.Count-1 should be the oldest.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Aug 01, 2016 3:32 am

Hmm.. Not working. Do I do:

System > Pick nth instance
Object: object
Instance: object.count-1

or

System > Pick nth instance
Object: object
Instance: -1
Check out my games on Google Play:

BEAST ATTACK (960,000+ downloads!)

ZOMBIE BASH (Android) (Launched Feb 17)

ZOMBIE BASH (iOS) (Launched March 17)
B
50
S
15
G
2
Posts: 427
Reputation: 5,164

Post » Mon Aug 01, 2016 3:43 am

Got it, it was instance 0. But first you may need a "pick all sprite" condition. The IID is an indexed list of only currently picked objects - so depending on how you had your events set up, if you just created one, that would be the only picked instance, therefore Sprite(0) is that one. If you pick them all, Sprite(0) is the oldest. Here is an example - https://www.dropbox.com/s/am9vst1j6bl6ily/iid.capx?dl=0
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Aug 01, 2016 4:27 am

Thanks @oosyrag! I just needed to add the Pick All and that did it. Thanks!
Check out my games on Google Play:

BEAST ATTACK (960,000+ downloads!)

ZOMBIE BASH (Android) (Launched Feb 17)

ZOMBIE BASH (iOS) (Launched March 17)
B
50
S
15
G
2
Posts: 427
Reputation: 5,164


Return to How do I....?

Who is online

Users browsing this forum: bluesun66 and 8 guests