How do I make "FOR" loop subevents trigger in order? SOLVED

0 favourites
  • 11 posts
From the Asset Store
Game Triggers is as versatile as a Swiss army knife, and will be a great resource for any type of game you're creating.
  • Basically, here's the code. If I have 1+ enemycores (works fine with just 1), it starts assigning random values to random enemycores (probably because all 3 subevents trigger simultaneously).

    Please help me figure out how do I make events in Construct loops trigger in order; or at least how do I trigger something each time for goes full circle.

    Thanks

  • No, subevents are not triggered simultaneously, they are triggered in order.

    You are doing something wrong, but it's hard to say what from just this screenshot.

    So lets say enemycount=5, then you repeat this loop 5 times and update 5 enemycore instances (which IDs are 0,1,2,3,4).

    Is this correct?

    Are you sure you need to reset the global variable buildup_threat_lvl to 0 on every loop pass?

    Since you are setting it to 0, for enemycores with ID=1,2,3,4 the threat_lvl will be either 0 or 20 or 19 or -1 (depending on Line of sight conditions).

    I suggest you create a text field on your layout and use it for debugging.

    For example:

    DebugText append text "i=" & i

    DebugText append text " enemycores.picked=" & enemycores.PickedCount

    DebugText append text " buildup_threat_lvl=" & buildup_threat_lvl

    Add lines like this in several key points of your loop and you'll get much better understanding what's going on.

    By the way, why are you not using For loop? It will automatically increment "i" for you.

    For "i" from 0 to enemycount
      ....
      Front.ID=loopindex 
      ...
      Back.ID=loopindex
      ...
      enemycore.ID=loopindex
    [/code:2wv9uvr0]
  • Thanks, will switch to for (i just felt more familiar with repeat setup)

    Will do some debugging just now.

    And yepp, that is correct, 0/20/19/-1 is exactly what I want them to be.

  • Mk.II suffers from the same problem - values being assigned to wrong instances.

  • I didn't mean that For loop will fix this issue, it just makes the code easier to read.

    Could you provide an example of "wrong instances"?

    Your code looks ok, except for the part where you reset buildup_threat_lvl only starting from ID=1.

    So for ID=0 this variable could contain any value assigned to it somewhere else in your code. But hey, maybe this is what you need. If not, move this action to the beginning of the loop.

    Have you tried debugging? I would do something like this:

    If this doesn't help, could you share the CAPX? You can remove unrelated stuff from it.

  • Debugging made clear the fact that It always only assignes value to second instance (the one with i=1) and NEVER to i=0 (threat_lvl always 0). I'll keep on looking.

    UPD : further testing showed that even if you add 4 instances ---> the only one which gets the right threat lvl is #1. Very odd. I'll package the .capx in a bit.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • capx : https://goo.gl/KjZijp

    *instance standing with front (red part) towards the player is supposed to have threat of +25; while the one standing with the back to the player is -25

  • You need to move all your off-screen sprites to another layout. I believe they were causing most of the problems.

    As you know, in order to spawn objects Construct 2 needs at least 1 "default" instance of each object to be added to one of the layouts. But it should not necessarily be your main game layout. Create a blank layout, call it "Unused" and move all off-screen sprites there.

    I also made some changes to your code, see my comments in the event sheet.

    I added drag&drop behavior to enemies, try dragging them around, see if everything is working as it should.

    https://www.dropbox.com/s/cl5907ze1k2af ... .capx?dl=0

  • YAAAAY GOT FIXED

    The problem was that x2 fronts and x2 backs were assigned id=0 due to my spawn system malfunctioning.

    Sorry to bother, great thanks for the help

  • You need to move all your off-screen sprites to another layout. I believe they were causing most of the problems.

    As you know, in order to spawn objects Construct 2 needs at least 1 "default" instance of each object to be added to one of the layouts. But it should not necessarily be your main game layout. Create a blank layout, call it "Unused" and move all off-screen sprites there.

    I also made some changes to your code, see my comments in the event sheet.

    I added drag&drop behavior to enemies, try dragging them around, see if everything is working as it should.

    https://www.dropbox.com/s/cl5907ze1k2af ... .capx?dl=0

    Will check out, thanks a lot.

    Blank layout solution is top, cheers. Otherwise I would have tried to make all transparent stuff have 'destroy outside layout' (which would involve lots of clickery)

  • No worries!

    You actually can replace the whole loop with this:

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