I'm having trouble understanding the for loop logic in Construct. I've looked at the manual, tutorials, other forum posts, other .capx and I'm still confused.
The way I understand it is you make a for loop give it a starting number and a ending number once the loop runs it increments the index and once the number reaches the end point the for loop should stop. But it never stops it just runs forever.
The only way I've been able to get it to stop is to run it as a sub event under a compare two values event where I compare the index is less than a set number. But if I have to do that I don't understand the purpose of the beginning and end numbers in the for loop. If I'm having to run an outside comparison to tell it to step.
The ORIGINAL block of code is setup how I think it should work.
The FIXED block of code is the only way I've been able to get it to work.
Does it have to be nested in a trigger once event like on Start of Layout?
looks like you are using constants in your for loop... not variables.. at least one of them should be a variable.
for that kind of code you probably want to use Repeat.
I've used variables before for the ending position with the same result. I mean a variable is just a container for a integer , string, float, or boolean. I don't understand how using a variable number would cause it to work differently.
I'm guessing they are meant to be used as a sub-event under a trigger once event.
Develop games in your browser. Powerful, performant & highly capable.
try using function to call that loop event, so it will trigger once per call.
- For "blocks" from 1 to to 10 > create object
Quite simply, you're setting up a loop inside the main loop (which the event sheet is). Every tick, the loop is executed and 10 block objects are created. You need to restrain the execution one way or another if that is not what you want. The simplest method is adding a "start of layout" condition to the loop event.
VictoryX yes as Magistross says, you need some sort of condition so that is not "always happening", that's what I meant by using a variable...i.e. assuming the condition is not always true... otherwise if you use constants you are running that forloop 60 times per second indefinitely...