Concurrent Function Handling

Get help using Construct 2

Post » Tue Sep 02, 2014 10:57 pm

Hey all,

I'm having trouble with running a function that needs to run across multiple instances.

Basically, I want each soldier to call the "Attack" function, while passing in the Attacker and Defender as parameters. What I have below works fell for 1 pair of Soldiers, but as soon as I include more, that's when I run into problems.

If a pair is fighting, as soon as a new pair collides, they override the function and the previous pair stops fighting.

My question is, how do I get the objects to run the functions independently of one another? I had the variables set to non-static before, but they were getting reset to 0 and I therefore couldn't recall the Attack action for them to continue fighting.

Any help would be appreciated!

EDIT: Would the Store Instance behavior be of any use here?

Code.PNG
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 13
Reputation: 283

Post » Tue Sep 02, 2014 11:12 pm

In events 2 and 3 try using a For Each when calling your function.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Sep 02, 2014 11:20 pm

Hmm... that didn't seem to have any effect.

Updated code for reference (also cleaned up a couple things):

Code.PNG
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 13
Reputation: 283

Post » Tue Sep 02, 2014 11:56 pm

No I meant after picking all the TopSolderis/BottomSoldiers, run them through the function with a for each, in a subevent that just does the function call. Easier if you could post the capx if possible.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Sep 03, 2014 12:07 am

Here you are!

Battle Farm.capx
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 13
Reputation: 283

Post » Wed Sep 03, 2014 12:26 am

Sorry man I don't have the Store reference plugin (and I'm not familiar with it) and I'm about to go out. If nobody has solved it for you when I get back I'll take a look but I'm sure someone will jump in :)
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Sep 03, 2014 3:34 am

The wait is causing issues. Remove it and it seems to work (although I'm not sure what your actual requirements are). Also events 4-5 are redundant as I don't think they'll ever get triggered. A collision between a TopSoldier and BottomSoldier will always get triggered by events 2-3 AFAIK as they are executed first (top to bottom). I suggest too that you use the Browser plugin and watch the debug output in the Chrome Console. You are getting some Function related errors that are shown there. If you remove the wait, they also stop. After all that, it doesn't seem adding the for each I suggested does anything. I just know I've had problems when passing UIDs to functions if I don't do this. tl;dr find another wait to delay between attacks.

PS: not sure how I've missed the Store Reference plugin all this time.. looks handy :)
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Sep 04, 2014 1:50 am

Thanks for taking the time to look into my problem! I've fixed the problems that are causing the function errors. I guess it was because by the time the wait was complete, the function params didn't exist!

I'm still trying to figure out how to prevent newer instances of the same object type interrupting the recursion on my function. I've posted a new topic on it where I think I explained myself a little better (and provided a capx with no foreign plugins).

If you search "A question about local variables in recursive functions", you should be able to find it (can't post links yet).

And yeah, Store Reference seems really useful! Unfortunately, I don't think it will help me in this situation.
B
6
Posts: 13
Reputation: 283


Return to How do I....?

Who is online

Users browsing this forum: marcinkowski, unicornspitfire and 65 guests