For each and If not working as espected

0 favourites
  • 5 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • I want to do this:

    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 }
        }
    }
    [/code:1pq71eqq]
    
    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?
  • 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.

  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • [attachment=0:30cmb8t0][/attachment:30cmb8t0]

    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.

  • I don't know where the problem was. I started over (with a different logic) and works. Thanks!

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