Concurrent Function Handling

0 favourites
  • 8 posts
  • 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?

    [attachment=0:1ruc293l][/attachment:1ruc293l]

  • In events 2 and 3 try using a For Each when calling your function.

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

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

    [attachment=0:1q3fql2l][/attachment:1q3fql2l]

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

  • Here you are!

    [attachment=0:17oarr1r][/attachment:17oarr1r]

  • 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

  • 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

  • Try Construct 3

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

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

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