M
Merrick
Guest
Hi folks
I've been having a problem with the for loop. I'm probably just not understanding completely how it works yet, but...
Here's my goal/problem: an object that, when created, instantly places objects around itself in a grid pattern.
Here is the code that I am using to try and make this work in obj_grey's Create Event:
//Loop Variable
yrow = -32;
//Loop for placing attack squares
for (i=0; i<2; i+=1)
{
var xcolumn;
xcolumn =(32*i)-32;
instance_create(x+xcolumn,y+yrow,obj_red);
if (xcolumn >= 32)
{
i = 0;
yrow +=32;
if (yrow > 32)
{
break;
}
}
}
Here is a screenshot of the results:
As you can see, it seems to only place the first two squares and then stops. I'm perplexed as to why.
I noticed that if I change the for loop to read "for(i=0;1<3; i+=1)" instead, I get this:
Close... but I'm not sure why that changed anything...
I can't seem to get my head around this problem. Can anyone enlighten me?
I've been having a problem with the for loop. I'm probably just not understanding completely how it works yet, but...
Here's my goal/problem: an object that, when created, instantly places objects around itself in a grid pattern.
Here is the code that I am using to try and make this work in obj_grey's Create Event:
//Loop Variable
yrow = -32;
//Loop for placing attack squares
for (i=0; i<2; i+=1)
{
var xcolumn;
xcolumn =(32*i)-32;
instance_create(x+xcolumn,y+yrow,obj_red);
if (xcolumn >= 32)
{
i = 0;
yrow +=32;
if (yrow > 32)
{
break;
}
}
}
Here is a screenshot of the results:
As you can see, it seems to only place the first two squares and then stops. I'm perplexed as to why.
I noticed that if I change the for loop to read "for(i=0;1<3; i+=1)" instead, I get this:
Close... but I'm not sure why that changed anything...
I can't seem to get my head around this problem. Can anyone enlighten me?
Last edited by a moderator: