How do I stop a for each loop?

Not favoritedFavorited Favorited 0 favourites
  • 7 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • I know that this seems like a pretty easy task, and I thought it would be too, but for some reason no matter what I do, the loop keeps running. Stop Loop action? Nothing. Pause movement behavior? Nothing. Disable movement behavior? Well, it works temporarily but reenabling it shows that the loop continued in the background. Destroy player? Nothing. Burn it all down and close the browser? for some reason, nothing.

    It's actually a bit funny just how much the loop is resistant to being stopped, but I really need it to be stopped for the sake of the project. Any suggestions?

    Tagged:

  • It's hard to tell what is going on from the screenshot, what is setting the continue variable to false?

  • Just realised what you are trying to do, I don't think that will ever work.

    If I understand correctly continue will be set to false when a tween finishes, but the for loop will always end before any of those tweens are completed.

    Perhaps it would be better for you to explain what you are trying to do before anyone can help.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's hard to tell what is going on from the screenshot, what is setting the continue variable to false?

    Thanks for the response. It is set false when the RedUnit's isPaused bool is true, which happens when RedUnit collides with another RedUnit.

    That's my main goal: make the loop stop when RedUnit collides with another.

  • Just realised what you are trying to do, I don't think that will ever work.

    If I understand correctly continue will be set to false when a tween finishes, but the for loop will always end before any of those tweens are completed.

    Perhaps it would be better for you to explain what you are trying to do before anyone can help.

    Ah, I see. As I said above I am basically trying to do collision detection for the RedUnits so if they overlap they stop moving down a path (a series of Marker sprites). Right now I am using Tween for said movement. I don't think I can share the file to the project right now, but I should be able to in a few hours if necessary.

  • I think you are thinking about this the wrong way, because collisions won't take place in the middle of the loop, they either happen before or after, so you won't be able to stop the loop mid way.

    I think you want to do a few things:

    1. When a collision happens, stop all the tweens. This should stop all movement that is taking place.
    2. Check there is a collision before even starting the loop, if there is don't even start.

    It's very hard to figure out what is happening from looking at a screen shot, but I have a feeling that your continue variable doesn't have the value you want it to have, so every time the loop starts, new tweens are created.

    Just trying to help from glancing at the screen shot of your events, so don't take everything I write too seriously :)

  • I think you are thinking about this the wrong way, because collisions won't take place in the middle of the loop, they either happen before or after, so you won't be able to stop the loop mid way.

    I think you want to do a few things:

    1. When a collision happens, stop all the tweens. This should stop all movement that is taking place.
    2. Check there is a collision before even starting the loop, if there is don't even start.

    It's very hard to figure out what is happening from looking at a screen shot, but I have a feeling that your continue variable doesn't have the value you want it to have, so every time the loop starts, new tweens are created.

    Just trying to help from glancing at the screen shot of your events, so don't take everything I write too seriously :)

    I found my own solution by calling a function repeatedly instead; Thanks for the help though!

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