Looping functions for multiple instances?

Get help using Construct 2

Post » Tue Sep 16, 2014 6:58 pm

I have instances of an enemy that spawn every 5 seconds and have a "shoot" function that I want to loop that controls the enemies shooting, how do I get the function to run on each instance of the enemy independently? If I put a for each On Created all the enemies shoot at the exact same time, if I put a for each on the "shoot" function only the first enemy spawned shoots. Any help would be appreciated thanks.
B
45
S
16
G
2
Posts: 107
Reputation: 4,253

Post » Wed Sep 17, 2014 7:42 am

how about using "for each" ?
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
62
S
14
G
2
Posts: 286
Reputation: 6,576

Post » Wed Sep 17, 2014 9:46 am

For each enemy to get enemy.uid
Use a function callback and make the function.param the uId of the enemy
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,708

Post » Sat Sep 20, 2014 2:58 pm

DUTOIT wrote:For each enemy to get enemy.uid
Use a function callback and make the function.param the uId of the enemy


Maybe you could post an example capx, I'm still have trouble getting this work.
B
45
S
16
G
2
Posts: 107
Reputation: 4,253

Post » Mon Sep 22, 2014 8:59 am

2 tutorials with example capx in the tutorial section with callbacks.
Or paste an slimmed down example and we can work through it together.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,708

Post » Mon Sep 22, 2014 10:11 am

It's a classic picking problem.

If you don't pick an object instance inside the function definition, the function will work on all instances of that object.

Like DUTOIT said, you have to pass your object's UID to the function, and inside the function you need to use system's "pick by unique ID" using that parameter.
ImageImage
B
42
S
13
G
10
Posts: 164
Reputation: 7,625


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests