How do I pick the newest object?

Get help using Construct 2

Post » Tue Nov 03, 2015 4:35 pm

This may be a really simple problem, but I need to select the newest projectile, and only the newest projectile, and effect it. I've tried:

System: Pick Projectile instance -1 > Effect Projectile

After spawning in the projectile but none are effected. I also tried:

System: Pick Projectile instance Projectile.Count - 1 > Effect Projectile

But that only effects the first one. Both were sub-events of:

Mouse: On Left Button Clicked > Player: Spawn Projectile on Layer 1

The projectile has the bullet property, and so goes forward forever. The effect (which works) changes their angle. When they're "not effected" they just go straight. How do I pick the last spawned projectile and effect it?
B
5
S
2
Posts: 4
Reputation: 388

Post » Tue Nov 03, 2015 4:54 pm

actually if you put the action on the projectile right below the action spawning it, the spawned one will be picked by the action..

Edit: also using an "projectile on created" event should do the trick
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Nov 03, 2015 5:03 pm

LittleStain wrote:actually if you put the action on the projectile right below the action spawning it, the spawned one will be picked by the action..

Edit: also using an "projectile on created" event should do the trick


That works, thanks! I'm still getting used to C2 logic and thought that putting it there would effect all projectiles :P

I'll look into "projectile on created" as well, although it seems pretty self-explanatory.
B
5
S
2
Posts: 4
Reputation: 388

Post » Tue Nov 03, 2015 5:06 pm

Use the system.Pick by evaluate.

Then you can use the IID to pick them, and the sprite.count-1 to determine the last one.

sprite.IID=Sprite.count-1

that will select the last one created.
Last edited by jojoe on Tue Nov 03, 2015 9:43 pm, edited 1 time in total.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Tue Nov 03, 2015 6:50 pm

Then you can use the UID to pick them, and the sprite.count-1 to determine the last one.

sprite.UID=Sprite.count-1

that will select the last one created.

That will only work if Sprite is the only object type you have in your game. Using iid might work though.
B
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » Wed Nov 04, 2015 11:42 pm

I did not understand what effect you want to put the projectile? It seems to be difficult to catch the moving object so when it is spawned.
B
29
S
9
G
3
Posts: 280
Reputation: 4,187

Post » Thu Nov 05, 2015 2:43 pm

sielxm3d wrote:I did not understand what effect you want to put the projectile? It seems to be difficult to catch the moving object so when it is spawned.


I was changing its angle.
B
5
S
2
Posts: 4
Reputation: 388

Post » Thu Nov 05, 2015 6:05 pm

B
29
S
9
G
3
Posts: 280
Reputation: 4,187

Post » Thu Nov 05, 2015 7:59 pm

Message: BeowulfValidus is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
sielxm3d wrote:Take a look in this .capx:


Thanks! I already found a way though :P It's a bit more complicated, but it uses less sub-events, and that's important on the free version (which I have). A think there's also an angle function to make it a lot easier, but I haven't looked into it yet.
B
5
S
2
Posts: 4
Reputation: 388

Post » Wed Nov 18, 2015 7:07 pm

Ok, thanks mate.
B
29
S
9
G
3
Posts: 280
Reputation: 4,187

Next

Return to How do I....?

Who is online

Users browsing this forum: marc254 and 9 guests