For each and If not working as espected

Get help using Construct 2

Post » Fri Apr 25, 2014 8:28 pm

I want to do this:

Code: Select all
for(var i = 0; i < landed.width; i++)
{
    for(var j = 0; j < landed.height; j++)
    {
        if(landed[i,j] == 1 && created[i,j] == 0) { // DO THE ACTIONS }
    }
}


The thing is that the LAND object is created but the created[i,j] never is set to 1, so it keeps creating LAND objects every tick! What I'm doing wrong?
You do not have the required permissions to view the files attached to this post.
B
6
Posts: 18
Reputation: 592

Post » Fri Apr 25, 2014 8:48 pm

Whew, where to begin.
No idea if this is a sub event, so I can't tell if there is anything to stop it running every tick.
Also see the part where it says "Every tick", that is implied, so you can get rid of it.
As to why the landed, and created events aren't stopping the creation... you're not changing the created array.

Edit:
Wait you are changing it.
Image ImageImage
B
168
S
50
G
164
Posts: 8,236
Reputation: 105,591

Post » Fri Apr 25, 2014 8:57 pm

Why you say Im not changing the created array? The IF left says that the actions will trigger if created[x,y] = 0 and on the actions in the right, the first thing I do is created[x,y] = 1. That should stop the next iteration to enter in the action field! Don't it?
B
6
Posts: 18
Reputation: 592

Post » Fri Apr 25, 2014 9:11 pm

arrayforeach.capx


I made an example of the events, and it ran as expected, so there must be something else going on.
Btw running an array every tick like that is usually considered inefficient.
You do not have the required permissions to view the files attached to this post.
Image ImageImage
B
168
S
50
G
164
Posts: 8,236
Reputation: 105,591

Post » Sat Apr 26, 2014 3:35 pm

I don't know where the problem was. I started over (with a different logic) and works. Thanks!
B
6
Posts: 18
Reputation: 592


Return to How do I....?

Who is online

Users browsing this forum: Syazanie Amirin and 8 guests