How do I pick the last spawn unit instance?

Get help using Construct 2

Post » Wed Jan 28, 2015 7:27 am

How do I pick the last spawn unit instance from a Families?
B
7
Posts: 20
Reputation: 293

Post » Wed Jan 28, 2015 8:14 am

Maybe pick by highest IID
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Jan 28, 2015 8:24 am

^ Which event should I use to do that?
B
7
Posts: 20
Reputation: 293

Post » Wed Jan 28, 2015 9:38 am

Another way: every time you spawn a unit update a variable with it's unique id.

Code: Select all
variable: latestID


then

Code: Select all
sprite -> onCreated
               set variable latestID to sprite.UID


then when you want to pick the latest instance add this to the appropriate event:
Code: Select all
sprite -> pick by unique id [latestID]
Last edited by pirx on Wed Jan 28, 2015 5:51 pm, edited 1 time in total.
B
16
S
7
G
1
Posts: 158
Reputation: 3,125

Post » Wed Jan 28, 2015 10:40 am

thanks
B
7
Posts: 20
Reputation: 293

Post » Thu Jan 29, 2015 7:24 am

hsm4ever wrote:^ Which event should I use to do that?


sorry, the expression is (for a no-variable solution)

System: Pick Sprite by evaluating Sprite.IID = Sprite.Count - 1
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Fri Jan 30, 2015 4:49 am

thanks a lot
B
7
Posts: 20
Reputation: 293

Post » Fri Jan 30, 2015 5:15 am

hsm4ever wrote:thanks a lot


Or even System: Pick Sprite instance Sprite.count - 1 which is the "Pick nth instance" condition under "System" and does the same as the above.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to How do I....?

Who is online

Users browsing this forum: dop2000, mihirolover, tarek2 and 8 guests

cron