Functions killing everything

  • I had a game built and have things happen when an enemy is killed. Then I discovered Functions and starting converting everything over to calling functions. Now however, when I call my destroy enemy function, it kills all enemies on screen, when in the main event sheet, it just killed the enemy being hit. What am I doing wrong? Thanks!

  • When you call a function, previously picked objects are forgotten, which is probably what's going on here. A way around this would be to pass the enemy's UID as an argument to the function, then from that pick the enemy inside the function.

  • Okay, that makes sense to me. But for the life of me, I can't find anything about UID inside of a condition or action. I must be blind

  • ahh the joy of getting functions to pick - I've had so much fun with that

    any how this is how I usually do it...

    give your enemies a instance variable - then save the enemies UID to that variable .. when the enemy is hit - call the kill function and add the enemy.instance variable as a parameter.

    in the function use "pick enemy by uid" and set the UID to pick to function.paramater and then do what ever you want to that enemy instance.

  • Kali

    You might try my instances group plugin, to save picked objects by UID, then pass it into function by parameter.

  • yep - I've used your plugin for something like that in a few projects rexrainbow - love your plugins by the way!

  • Ah very nice. Thanks Kali! and Linkman2004! That works perfectly. Now to try rexrainbow's plugin

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You don't need plugins for this, just pass enemy.UID in the function parameter (say, param(0)), then in the function you do Pick object by unique ID = function.param(0)

  • You don't need plugins for this, just pass enemy.UID in the function parameter (say, param(0)), then in the function you do Pick object by unique ID = function.param(0)

    So, I set the id to a variable when the enemy is hit, then in the On call function I put the hit enemy logic. Then I use a return function, right?

  • No, you pass the ID into the function, pick it and do your actions.

  • oooh, I see what you guys are saying. Thanks so much everyone. This community is quite remarkable. I really appreciate the help and the example from blackhornet!

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