• Question
  • how to make a timer in a loop in a convenient way

what are you trying to get it to do

    Letti42
    well, im trying to make it so when the player clicks on a grid, it sets a timer to execute those lines of code.
    (it's some ore mining game thingy)

    for (var gridI = 0; gridI < grids.length; gridI++) {
            if (mouseIsOver(grids[gridI]) && mouseWentDown("leftButton")) {
              grids[gridI].destroy();
              grids.splice();
              for (var stonesI = 0; stonesI < stones.length; stonesI++) {if (mouseIsOver(stones[stonesI]) && mouseWentDown("leftButton")) {cash += oreStats.stone.cash;}}
              for (var goldsI = 0; goldsI < golds.length; goldsI++) {if (mouseIsOver(golds[goldsI]) && mouseWentDown("leftButton")) {cash += oreStats.gold.cash;}}
              for (var topazesI = 0; topazesI < topazes.length; topazesI++) {if (mouseIsOver(topazes[topazesI]) && mouseWentDown("leftButton")) {cash += oreStats.topaz.cash;}}
              for (var emeraldsI = 0; emeraldsI < emeralds.length; emeraldsI++) {if (mouseIsOver(emeralds[emeraldsI]) && mouseWentDown("leftButton")) {cash += oreStats.emerald.cash;}}
              for (var rubiesI = 0; rubiesI < rubies.length; rubiesI++) {if (mouseIsOver(rubies[rubiesI]) && mouseWentDown("leftButton")) {cash += oreStats.ruby.cash;}}
              for (var sapphiresI = 0; sapphiresI < sapphires.length; sapphiresI++) {if (mouseIsOver(sapphires[sapphiresI]) && mouseWentDown("leftButton")) {cash += oreStats.sapphire.cash;}}
              for (var amethystsI = 0; amethystsI < amethysts.length; amethystsI++) {if (mouseIsOver(amethysts[amethystsI]) && mouseWentDown("leftButton")) {cash += oreStats.amethyst.cash;}}
              for (var diamondsI = 0; diamondsI < diamonds.length; diamondsI++) {if (mouseIsOver(diamonds[diamondsI]) && mouseWentDown("leftButton")) {cash += oreStats.diamond.cash;}}
              for (var plutonitesI = 0; plutonitesI < plutonites.length; plutonitesI++) {if (mouseIsOver(plutonites[diamondsI]) && mouseWentDown("leftButton")) {cash += oreStats.diamond.cash;}}
            }
          }

      pluto why are you using the splice protocol like that? if anything you should remove the sprite after acessing it's properties as well... splice(index: number, amount: length) should also be filled in especially if your removing it from the array

        pluto well i'd say that would likely be the cause of your issue, not to mention that your not accounting for removing a sprite from your loop meaning when one is removed from the index it'll completely skip over another active one which will be weird af behaviors.... though i guess my suggestion wasn't clear enough when I posted my original response, when your removing the part of the array from the loop since your incrementing you should also decrement from it when you remove something from it, since your using gridI as your iterator you can use gridI-- or gridI -= amountRemoved; that way all elements within your loop remain covered.... though I'm still uncertain if this is what you wanted clarification on not to mention that splicing the grid and destroying the element on the grid should also come last especially if there are properties that you are using on it when comparing what to execute in your case as well

        Chat