Bool value being ignored by IF statement

This code seems to be ignoring the fact that the bool foundAllMatches is true. I want the code to continue to check for matches until finds none; the CheckForMatches method is supposed to keep happening until it finds no more matches and restores the foundAllMatches bool to true.

As soon as I hit Run, I see the repeating debug message “Checking for matches . . .”. I’m pretty sure I should only see that when the mouse button is clicked, and then it should stop as soon as there are no more matches.

void Start()
{
foundAllMatches = true;
}

private void Update()
{
if (IsActive == 0 && Input.GetMouseButton(0) == false && foundAllMatches == false)
{
CheckForMatches();
}

if (Input.GetMouseButtonDown(0))
{
foundAllMatches = false;
}
}

private void CheckForMatches()
{
Debug.Log(“Checking for matches . . .”);

//----THIS IS WHERE matchesFound IS DETERMINED (no problems here)----

if (matchesFound == 0)
{
foundAllMatches = true;
}
}

well… your soultion is kind of like this:

void Start()
{
	foundAllMatches = true;
}

private void Update()
{
	if(IsActive == 0 && !Input.GetMousebutton(0) && !foundAllMatches){
		CheckForMatches();
		while(foundAllMatches){
			CheckForMatches();
		}
	}
	
	if (Input.GetMouseButtonDown(0))
	{ 
		foundAllMatches = false; 
	}
}


private void CheckForMatches()
{
	Debug.Log("Checking for matches . . .");

	//----THIS IS WHERE matchesFound IS DETERMINED (no problems here)----

	if (matchesFound == 0) 
	{
		foundAllMatches = true; 
	}
}

However, I would be remiss to not tell you that running that while is a bad idea in an update. It could easily lead to an infinite loop if everything does not fall into place. I would consider redoing the method of which you are doing this to not lead to such a loop.

Thanks for the reply. However, I want it to stop looking for matches when it’s determined it’s found them all. In your version, line 10 would be:

If you remove this code from your Update method, does it still have the issue?

if (Input.GetMouseButtonDown(0))
{
foundAllMatches = false;
}

I would not expect it to be the cause but if you are clicking play and the scene loads while your left mouse button is down, it may (?) catch it in the first frame of the game which would override the assignment in Start.

Hard to tell without seeing the rest of the code. First step I would say is as simple as adding in debug statements so you can see the value of relevant variables at each point.