I have the following simple script:
private IEnumerator queueAndCheckForMatch()
{
_director.OnCheckForMatchSucceeded += (caller, queuedMatch) =>
{
if (queuedMatch != null)
{
_match = queuedMatch;
_searchingForMatch = false;
ShowMatchFound();
}
};
_searchingForMatch = true;
Debug.Log(string.Format("SearchingForMatch set to: {0}", _searchingForMatch));
Debug.Log(string.Format("Party is null {0}", Party == null));
if (Party != null)
{
Debug.Log(string.Format("SearchingForMatch at point of while start: {0}", _searchingForMatch));
while (_searchingForMatch)
{
Debug.Log(string.Format("While entered: {0}", _searchingForMatch));
yield return StartCoroutine(_director.CheckForMatch(Party.PartyId));
Debug.Log(string.Format("Wait for seconds reached: {0}", _searchingForMatch));
yield return new WaitForSeconds(1);
Debug.Log(string.Format("Wait for seconds lapsed: {0}", _searchingForMatch));
}
}
}
All it does is make a call to a server to see if a match can be made between two opponents. If the server cannot make a match the script waits for one second and then tries again. If a match is found _searchingForMatch becomes false and it stops attempting to find a new match.
When I run this script it never makes it to the first yield statement. The output in the console shows only two debug messages. “SearchingForMatch set to: True” and “Party is null False”. That would tend to indicate it stops execution on this line:
if (Party != null)
And when I debug it the point of execution gets to the following line and then abruptly stops.
while (_searchingForMatch)
I’m at a bit of a loss and would appreciate any suggestions as to what the problem may be. This code worked just fine before I tried to make it check each second. The working code looked like this.
private IEnumerator queueAndCheckForMatch()
{
_director.OnCheckForMatchSucceeded += (caller, queuedMatch) =>
{
if (queuedMatch != null)
{
_match = queuedMatch;
ShowMatchFound();
}
};
if (Party != null)
{
yield return StartCoroutine(_director.CheckForMatch(Party.PartyId));
}
}