Stuck in a WHILE loop

0 favourites
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies. For use in game and custom works.
  • Although my inverted condition should be returning false, as the global variables now match, I never leave the damn WHILE loop?!

  • What are you using to determine that you are not leaving the while loop, what is happening?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I am randomising positions until nothing overlaps. I am spawning an object, increasing a counter. I am then checking if any instances overlap, if they do...I destroy the object and decrease the counter. This repeats until the counter reaches the desired value (required instances). My understanding of While is, it leaves the loop when the condition inside the loop is False. My IF statement comparing the variables should evaluate to false when the number of instances matches the required number of instances. I can see from the debugger, they are equal (3), so the criteria (System get value) should evaluate to false and leave the While loop.

  • And it will exit the loop, so what is happening that you are not expecting? What is the outcome? You've covered the actions in the screenshot.

  • It never exits the loop....you can see in my screenshot the two variables are both 3. This should make the WHILE condition false. Infinite loop however...maybe it’s a bug when using an inverted condition (logical Not).

  • Nope not a bug, it will stop the loop if the conditions are met. I can see that the variables are both 3 but nothing else as you covered the events with the viewer. You haven't mentioned why you think the loop is still ongoing or what is really happening.

  • When I step through on the debugger, it just keeps iterating through first task, and never leaves. The game never loads in normal, non-debug mode. Stepping through, the iterations just keep going. You don’t need to know the right hand side. The screenshot shows the conditions are met, but iteration continues.

    I will post without debugger in the way tomorrow.

  • You need to move the condition from sub-event to event #60. "While" and the condition should be in the same event.

    I also suggest always adding this "emergency" exit condition to While loops, to prevent infinite loops: loopindex<1000

  • quick question, why are you inverting a = value comparison ? u could easily say not equal instead of equal + inverted... might be that the inverted trows a error? did u check the console of the browser? not the debug console.

  • You need to move the condition from sub-event to event #60. "While" and the condition should be in the same event.

    I also suggest always adding this "emergency" exit condition to While loops, to prevent infinite loops: loopindex<1000

    Hi,

    I realise now that I was expecting one of the sub events conditions evaluating to False to cause the WHILE loop to exit, so thanks - it has to be in the same event. Still an issue though, the overlap test is not working. So I can get out of the WHILE loop but it is still leaving overlapped sprites. Can you not check for overlap in the same frame you spawned then?

  • > You need to move the condition from sub-event to event #60. "While" and the condition should be in the same event.

    > I also suggest always adding this "emergency" exit condition to While loops, to prevent infinite loops: loopindex<1000

    Hi,

    I realise now that I was expecting one of the sub events conditions evaluating to False to cause the WHILE loop to exit, so thanks - it has to be in the same event. Still an issue though, the overlap test is not working. So I can get out of the WHILE loop but it is still leaving overlapped sprites. Can you not check for overlap in the same frame you spawned then?

    Regards

    S

    you should be able to check for overlaps once the item is created, but i think since the overlap checking is under a function you could easily drag the subevent from under while and place it under the function as now u have

    Function

    ---while subevent

    ------subevent with while as parent

    what im suggesting is

    function

    ---while subevent

    ---check for overlap (with function as parent) -- this way gives it a bit of time to create the items, then check the overlap.

    not sure if will work, but logically it should... unless we understand wrong the while loop.

    Edit2: if u can use the overlap check on a everytick id separate the "overlap condition" outside the function, and run it always basically... if that is a posibility that will definetly work, just not sure how will affect ur gameplay/system u built, and if u need that!

  • Hi,

    I got it working by placing the overlap check into an every tick event, which should only run after the initial creation. So I dont destroy objects now, in the Every Tick event, I move the positions around.

    Not sure if I have to pin and unpin before setting the position. Can you set the position of a pinned object, as I am pinning it during object creation.

  • yes you have to unpin/change position>then pin it back on the object .... i don't think construct changed the way u pin objects ... but as i remember back in C2 u couldn't change the position of an object if was already pined. i mean u could setup the event, but would be overridden by the pin behavior so u wouldn't see any difference.

    btw that everytick condition is not needed, you can run the if inverted condition alone, and will act as a everytick condition. and same applies to every other condition that doesn't have that green arrow on it which means trigger one time.

  • Thanks. In that case, what is every tick for?

  • Thanks. In that case, what is every tick for?

    for actions that don't need a condition, like updating text everytick... or making something move on a loop without having a condition to change its movement (like a solar eclipse or moon/day moving in ur game, or a score update something of that sort.).

    now u can run everytick or just have a condition... and basically if the condition is always true... = everytick... that action will always fire.

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