How do I pick the newest object?

  • 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?

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • [quote:8pibyrav]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.

  • 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 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.

  • 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.

  • Ok, thanks mate.

  • Hei [quote:31jk5njw]BeowulfValidus

    how you do this solution, i am having a same problem.

  • Try this out.

    http://www.sizzle-games.com/last.capx

    One way, left click mouse to pick last created (newest) instance, and change its angle.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)