Functions killing everything

Get help using Construct 2

Post » Sun Feb 14, 2016 7:11 am

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!
B
6
Posts: 30
Reputation: 310

Post » Sun Feb 14, 2016 7:19 am

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.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Sun Feb 14, 2016 8:55 am

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 :shock:
B
6
Posts: 30
Reputation: 310

Post » Sun Feb 14, 2016 12:21 pm

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.
Image
Get it on Google play or play on papio.nu
B
11
S
2
Posts: 79
Reputation: 786

Post » Sun Feb 14, 2016 1:47 pm

@Kali

You might try my instances group plugin, to save picked objects by UID, then pass it into function by parameter.
B
109
S
27
G
277
Posts: 4,482
Reputation: 154,924

Post » Sun Feb 14, 2016 1:53 pm

yep - I've used your plugin for something like that in a few projects @rexrainbow - love your plugins by the way!
Image
Get it on Google play or play on papio.nu
B
11
S
2
Posts: 79
Reputation: 786

Post » Sun Feb 14, 2016 7:00 pm

Ah very nice. Thanks Kali! and Linkman2004! That works perfectly. Now to try rexrainbow's plugin :D
B
6
Posts: 30
Reputation: 310

Post » Sun Feb 14, 2016 7:36 pm

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)
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Sun Feb 14, 2016 11:25 pm

7Soul wrote: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?
B
6
Posts: 30
Reputation: 310

Post » Sun Feb 14, 2016 11:34 pm

No, you pass the ID into the function, pick it and do your actions.
www.blackhornettechnologies.com/Constru ... ction.capx
ImageImageImage
B
71
S
22
G
249
Posts: 3,763
Reputation: 138,577

Next

Return to How do I....?

Who is online

Users browsing this forum: Christmas, wizdigitech, Yahoo [Bot] and 27 guests