I can't seem to get a game to appear in the list when I poll the Master Server. Where did I go wrong? Code (csharp): var redPrefab : Transform; var bluePrefab : Transform; var redSpot : GameObject; var blueSpot : GameObject; var gamesName = "Enter the name of your game!"; var gamesDesc = "Enter a short description of your game!"; var gameMaster = false; var gameJoiner = false; function OnGUI () { if (!gameMaster !gameJoiner) { if (GUILayout.Button("Create Game")) { gameMaster=true; } if (GUILayout.Button("Join Game")) { gameJoiner=true; } } if (gameMaster == true){ gamesName = GUILayout.TextField(gamesName); gamesDesc = GUILayout.TextArea(gamesDesc); if (GUILayout.Button ("Create Game")) { Network.useNat = !Network.HavePublicAddress(); Network.InitializeServer(32, 25002); MasterServer.RegisterHost("RandomBoxWithCubesGame",gamesName,gamesDesc); } } if (gameJoiner == true) { MasterServer.ClearHostList(); MasterServer.RequestHostList("RandomBoxWithCubesGame"); if (MasterServer.PollHostList().length != 0) { var hostData: HostData[] = MasterServer.PollHostList(); for (var i:int=0; i<hostData.length; i++) { GUILayout.Button(hostData[i].gameName+": "+hostData[i].comment); } MasterServer.ClearHostList(); } } }
have look at the code I supplied here: http://forum.unity3d.com/viewtopic.php?t=7739 It has a working Master Server implementation... well it works here... :wink: Cheers.
I couldn't find anything different between yours and mine. I took code directly out of the documentation. The only difference in my script from the docs is that I want to display "Game Name: Game Description" in a GUI Button. BTW, here's the most recent version, which still doesn't work. Code (csharp): var redPrefab : Transform; var bluePrefab : Transform; var redSpot : GameObject; var blueSpot : GameObject; var gamesName = "Enter the name of your game!"; var gamesDesc = "Enter a short description of your game!"; var gameMaster = false; var gameJoiner = false; function OnGUI () { if (!gameMaster !gameJoiner) { if (GUILayout.Button("Create Game")) { gameMaster = true; } if (GUILayout.Button("Join Game")) { gameJoiner = true; } } if (gameMaster == true){ gamesName = GUILayout.TextField(gamesName); gamesDesc = GUILayout.TextArea(gamesDesc); if (GUILayout.Button ("Create Game")) { Network.useNat = !Network.HavePublicAddress(); Network.InitializeServer(32, 25002); MasterServer.RegisterHost("RandomBoxWithCubesGame",gamesName,gamesDesc); } } if (gameJoiner == true) { if (MasterServer.PollHostList().length != 0) { var hostData: HostData[] = MasterServer.PollHostList(); for (var i:int=0; i<hostData.length; i++) { GUILayout.Button(hostData[i].gameName+": "+hostData[i].comment); } MasterServer.ClearHostList(); } } } function Awake () { MasterServer.ClearHostList(); MasterServer.RequestHostList("RandomBoxWithCubesGame"); }
put some error checking in there. that might help you track down the issue: Code (csharp): function OnFailedToConnectToMasterServer(info: NetworkConnectionError) { Debug.Log("Could not connect to master server: "+ info); } cheers.
It doesn't return anything. I guess that means that its connecting all right, but not displaying anything for some reason?
Hmm, upon further investigation, if I put the "if(gamejoiner)" block in Update instead of OnGUI, and change GUILayout.Button to Debug.Log it returns everything fine. I must now work at getting that information into the GUI.