Execution for loop problem

0 favourites
  • 7 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • I'm a neophyte of Constrct 3, and I'm experiencing problems handling a for loop.

    As you can see from the screen below, I would like to make it so that when a certain condition occurs, the loop is interrupted and I would also like to exit the execution of that certain event. In practice I would like to make sure that the sub-event below the loop exit action is not executed, while now, even if I tell the loop to end, the check event below seems to execute anyway.

    Can anyone tell me what I'm doing wrong?

  • Hiya! Here's an excerpt from the manual:

    Stop loop

    Stop a Repeat, For or For each loop currently running. These loops are system conditions. The rest of the event's actions and subevents will still complete, but the loop will not run any further after that.

    This means that in your logic here, the loop is stopped but Construct still executes the remaining sub-event.

    You need to restructure your events :)

  • What is height-1 value of the array and what is the value printed for loopindex on the middle event? Are they the same? When you stop the loop it will run the sub event and if the condition is true then it will run the action.

  • Thanks for the responses.

    I was hoping that the "Stop loop" action would work like a break; command in the nromal programming (so the loop is immediately stopped) but apparently it doesn't work that way.

    My goal was to recreate via events such an event:

    	n = TableArrai.height -1;
    	for(int i = 0; i < n; i++){
     if(board[x][i] != 0) {
     	break;
    	}
     if(i == n-1){
     //Player win
     }
    

    lionz height-1 is the value I need to properly cycle all the cells in my grid (2d array). Starting from 0 I subtract 1 from the height of the array.

  • It does work that way, that's why I'm trying to understand the problem here. When the loop stops it runs the sub events once more, but it would only run it if the condition is true, it would mean the value to stop the loop is found at the end of the array.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Since you don't eisste a "break;" command, I was able to solve it by using a boolean control variable.

    Thanks for the help though!

  • You've moved the condition though. Before it was a sub event of the top condition and now it's underneath it at the same level. So maybe that was your problem.

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