From 4c145a672a65bb4d79916f194fb5075f71f58623 Mon Sep 17 00:00:00 2001
From: baletiballo <75846481+baletiballo@users.noreply.github.com>
Date: Mon, 17 Feb 2025 15:46:36 +0100
Subject: [PATCH] waitingForLocalMMT now prints correct debug statements

It now logs it`ll wait *before* waiting, and "Preparing game now" once the connection is established.
---
 .../Scripts/UI/NetwMenu/WaitingForLocalMMT.cs | 27 +++++++++----------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/Assets/Scripts/UI/NetwMenu/WaitingForLocalMMT.cs b/Assets/Scripts/UI/NetwMenu/WaitingForLocalMMT.cs
index 0cea37ab..8c158427 100644
--- a/Assets/Scripts/UI/NetwMenu/WaitingForLocalMMT.cs
+++ b/Assets/Scripts/UI/NetwMenu/WaitingForLocalMMT.cs
@@ -23,30 +23,29 @@ void PrepareGame()
         {
             CommunicationEvents.ServerAdress = "http://" + CommunicationEvents.ServerAddressLocal; //ServerAddress needs the "http://"
             //UnityEngine.Debug.Log("StartMainMenu");
+            // TODO: Display "Loading in progress" to the player
             SceneManager.LoadScene("MainMenu");
         }
     }
 
     IEnumerator ServerRoutine()
     {
-        while (true)
-        {
-            yield return ServerSlots[ServerSlot.localServer].UpdateServerStatus(skipIfAlreadyChecked: false);
-
-            // The address of the localServer currently cannot change, so it is never empty/illegal
-            // If this can happen in the future, this condition may not suffice
-            if (ServerSlots[ServerSlot.localServer].currentStatus == ServerStatus.online)
-            {
-                CommunicationEvents.ServerRunning = true;
-                PrepareGame();
-            }
+        yield return ServerSlots[ServerSlot.localServer].UpdateServerStatus(skipIfAlreadyChecked: false);
 
-            //Wait for 2 seconds
+        // The address of the localServer currently cannot change, so it is never empty/illegal
+        // If this can happen in the future, this condition may not suffice
+        while (ServerSlots[ServerSlot.localServer].currentStatus != ServerStatus.online)
+        {
+            Debug.Log("Local MMT Server not ready yet\n Will try again in 2 sec.");
             yield return new WaitForSecondsRealtime(2f);
-            print("waiting");
+            yield return ServerSlots[ServerSlot.localServer].UpdateServerStatus(skipIfAlreadyChecked: false);
         }
 
-
+        Debug.Log("Preparing game now");
+        CommunicationEvents.ServerRunning = true;
+        // Give Unity time to flush the debug log
+        yield return new WaitForSecondsRealtime(0.1f);
+        PrepareGame();
     }
 
     public UnityWebRequest pingL()
-- 
GitLab