Search Unity

MasterServer Trouble

Discussion in 'Scripting' started by nickavv, Nov 18, 2007.

  1. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    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):
    1. var redPrefab : Transform;
    2. var bluePrefab : Transform;
    3. var redSpot : GameObject;
    4. var blueSpot : GameObject;
    5. var gamesName = "Enter the name of your game!";
    6. var gamesDesc = "Enter a short description of your game!";
    7. var gameMaster = false;
    8. var gameJoiner = false;
    9.  
    10. function OnGUI () {
    11.     if (!gameMaster  !gameJoiner) {
    12.         if (GUILayout.Button("Create Game")) {
    13.             gameMaster=true;
    14.         }
    15.         if (GUILayout.Button("Join Game")) {
    16.             gameJoiner=true;
    17.         }
    18.     }
    19.     if (gameMaster == true){
    20.         gamesName = GUILayout.TextField(gamesName);
    21.         gamesDesc = GUILayout.TextArea(gamesDesc);
    22.         if (GUILayout.Button ("Create Game")) {
    23.             Network.useNat = !Network.HavePublicAddress();
    24.             Network.InitializeServer(32, 25002);
    25.             MasterServer.RegisterHost("RandomBoxWithCubesGame",gamesName,gamesDesc);
    26.         }
    27.     }
    28.     if (gameJoiner == true) {
    29.         MasterServer.ClearHostList();
    30.         MasterServer.RequestHostList("RandomBoxWithCubesGame");
    31.         if (MasterServer.PollHostList().length != 0) {
    32.             var hostData: HostData[] = MasterServer.PollHostList();
    33.             for (var i:int=0; i<hostData.length; i++) {
    34.                 GUILayout.Button(hostData[i].gameName+": "+hostData[i].comment);
    35.             }
    36.             MasterServer.ClearHostList();
    37.         }
    38.     }
    39. }
     
  2. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
  3. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    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):
    1. var redPrefab : Transform;
    2. var bluePrefab : Transform;
    3. var redSpot : GameObject;
    4. var blueSpot : GameObject;
    5. var gamesName = "Enter the name of your game!";
    6. var gamesDesc = "Enter a short description of your game!";
    7. var gameMaster = false;
    8. var gameJoiner = false;
    9.  
    10. function OnGUI () {
    11.     if (!gameMaster  !gameJoiner) {
    12.         if (GUILayout.Button("Create Game")) {
    13.             gameMaster = true;
    14.         }
    15.         if (GUILayout.Button("Join Game")) {
    16.             gameJoiner = true;
    17.         }
    18.     }
    19.     if (gameMaster == true){
    20.         gamesName = GUILayout.TextField(gamesName);
    21.         gamesDesc = GUILayout.TextArea(gamesDesc);
    22.         if (GUILayout.Button ("Create Game")) {
    23.             Network.useNat = !Network.HavePublicAddress();
    24.             Network.InitializeServer(32, 25002);
    25.             MasterServer.RegisterHost("RandomBoxWithCubesGame",gamesName,gamesDesc);
    26.         }
    27.     }
    28.     if (gameJoiner == true) {
    29.         if (MasterServer.PollHostList().length != 0) {
    30.             var hostData: HostData[] = MasterServer.PollHostList();
    31.             for (var i:int=0; i<hostData.length; i++) {
    32.                 GUILayout.Button(hostData[i].gameName+": "+hostData[i].comment);
    33.             }
    34.             MasterServer.ClearHostList();
    35.         }
    36.     }
    37. }
    38.  
    39. function Awake () {
    40.     MasterServer.ClearHostList();
    41.     MasterServer.RequestHostList("RandomBoxWithCubesGame");
    42. }
     
  4. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    put some error checking in there. that might help you track down the issue:

    Code (csharp):
    1.  
    2. function OnFailedToConnectToMasterServer(info: NetworkConnectionError)
    3. {
    4.     Debug.Log("Could not connect to master server: "+ info);
    5. }
    6.  
    cheers.
     
  5. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    It doesn't return anything. I guess that means that its connecting all right, but not displaying anything for some reason?
     
  6. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    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.