Hello. I am working on a planet puzzle league style game. I have one function that checks too see if there are any groups of 3 sequential colors and destroys them. At the end of this function, I call another function that causes the blocks above the destroyed blocks to fall. This all works fine, but my problem comes in what to do next. After the blocks fall, I need to invoke the first function again (in order to see if there are any matches created from the tiles falling). But I cannot do this because it creates a loop. I have tried using InvokeRepeating on the first function, using a series of conditions, and combining it into one function but nothing works.
I don’t understand your problem. Wouldn’t you want to check for sets of 3 all the time, since any interaction can potentially create a group of three?
The only issue I can think you are having is that this constant loop would not allow you to interact with the app. If that is what you mean I would suggest putting the loop into an IEnumerator and adding a return command to allow for user input or go over the options listed here:
The function that checks your board should only be called once per frame. A good place for that would be Update() on your board. This will allow you to cleanly evaluate the board without doing wacky stuff during moves.
That’s what the answer in the link I provided suggests first and then gives what I suggest using IEnumerators. Thing is the state of IEnumerators is checked each frame from what I understand, so basically it depends on how you want to structure things.
Currently I only call the CheckForMatches function when the player does something (clicking the button that adds a new row of tiles to the screen or swap the position of two tiles).
If your 3-in-a-row function finds anything and gets rid of it, then run your fall-down function and then run the 3-in-a-row function again, until the 3-in-a-row function doesn’t find anything.
The key there is whether or not it’s finding anything. You quit repeating when it quits finding anything.
Maybe you should always check for matches in the update function. So its constantly checking for matches. If there is a match, then call the Fall() function. After the fall function is done it does not need to call a Match() function because the update function is doing it anyway.
function Update(){
Check for matches
Destroy those tiled
if(any tiles == null)
Fall();
}
function Fall(){
Move tiles down
}