Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Help! Errors are killing my noob mind!!!

Discussion in 'Scripting' started by UnitMC, Feb 24, 2021.

  1. UnitMC

    UnitMC

    Joined:
    Dec 13, 2020
    Posts:
    3
    I am getting a few Errors... what do they mean?
    My Code:

    Code (CSharp):
    1. using Photon.Pun;
    2. using Photon.Realtime
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6.  
    7. public class CustemMatchmaking : MonoBehaviourPunCallbacks
    8. {
    9.     [SerializeField]
    10.     private GameObject lobbyConnectButton;
    11.     [SerializeField]
    12.     private GameObject lobbyPanel;
    13.     [SerializeField]
    14.     private GameObject mainPanel;
    15.     [SerializeField]
    16.     public InputField playerNameInput;
    17.  
    18.     private    string roomName;
    19.     private int roomSize;
    20.  
    21.     private List<RoomInfo> roomListings;
    22.     [SerializeField]
    23.     public Transform roomsContainer;
    24.     [SerializeField]
    25.     private GameObject roomListingPrefab;
    26.  
    27.     public override void OnConnectedToMaster()
    28.     {
    29.     PhotonNetwork.AutomaticallySyncScene = true;
    30.     lobbyConnectButton.SetActive(true);
    31.     roomListings = new List<RoomInfo>();
    32.  
    33.     if(PlayerPrefs.Haskey("Nickname"))
    34.     {
    35.         if (PlayerPrefs.GetString("NickName") == "")
    36.         {
    37.             PhotonNetwork.NickName = "Player " + Random.Range(0, 1000);
    38.         }
    39.         else
    40.         {
    41.             PhotonNetwork.NickName = PlayerPrefs.GetString("NickName");
    42.         }
    43.     }
    44.     else
    45.     {
    46.         PhotonNetwork.NickName = "Player" + Random.Range(0, 1000);
    47.     }
    48.     playerNameInput.text = PhotonNetwork.NickName;
    49.     }
    50.  
    51.  
    52.     public void JoinLobbyOnClick()
    53.     {
    54.         mainPanel.SetActive(false);
    55.         lobbyPanel.SetActive(true);
    56.         PhotonNetwork.JoinLoby();
    57.     }
    58.    
    59.     public override void OnRoomListUpdate(List<RoomInfo> roomList)
    60.     {
    61.         int tempIndex;
    62.         foreach (RooomInfo room in roomList)
    63.         {
    64.             if (roomListings != null)
    65.             {
    66.                 tempIndex = roomListings.FindIndex(ByName(room.Name));
    67.             }
    68.             else
    69.             {
    70.                 tempIndex = -1;
    71.             }  
    72.             if (tempIndex != -1)
    73.             {
    74.                 roomListings.RemoveAt(tempIndex);
    75.                 Destroy(roomsContainer.GetChid((tempIndex).gameObject);
    76.             }      
    77.             if (room.PlayerCount > 0)
    78.             {
    79.                 roomListings.Add(room);
    80.                 ListRoom(room);
    81.             }
    82.  
    83.         }
    84.  
    85.     }
    86.  
    87.     static System.Predicate<RoomInfo> ByName(string name)
    88.     {
    89.         return delegate (RoomInfo room)
    90.         {
    91.             return room.Name == name;
    92.         };
    93.     }
    94.  
    95.     void ListRoom(RoomInfo room)
    96.     {
    97.         if (room.IsOpen && room.IsVisible)
    98.         {
    99.             GameObject tempListing = Instantiate(roomListingPrefab, roomsContainer);
    100.             RoomButton tempButton = tempListing.GetComponent<RoomButton>();
    101.             tempButton.SetRoom(room.Name, room.MaxPlayers, room.PlayerCount);
    102.         }
    103.     }
    104.  
    105.     public void OnRoomNameChanged(string nameIn)
    106.     {
    107.         roomName = nameIn;
    108.     }
    109.     public void OnRoomSizeChanged(string sizeIn)
    110.     {
    111.         roomSize = int.Parse(sizeIn);
    112.     }
    113.  
    114.     public  void CreateRoom()
    115.     {
    116.         Debug.Log("Creating room now")
    117.         RoomOptions roomOps = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = (byte)roomSize };
    118.         PhotonNetwork.CreateRoom(roomName, roomOps);
    119.     }
    120.     public override void OnCreateRoomFailed(short returnCode, string message)
    121.     {
    122.         Debug.Log("Failed to create room. Choose other name or wait a bit then try again.");
    123.     }
    124.     public void MatchmakingCancel()
    125.     {
    126.         mainPanel.SetActive(true);
    127.         lobbyPanel.SetActive(false);
    128.         PhotonNetwork.LeaveLobby()
    129.     }
    130.    
    131.  
    132.  
    133.  
    134.  
    135. }
    136.  
    137.  
     

    Attached Files:

  2. UnitMC

    UnitMC

    Joined:
    Dec 13, 2020
    Posts:
    3
    The errors are in the attached file...
     
  3. simiel7

    simiel7

    Joined:
    Dec 18, 2020
    Posts:
    7
    As UnitMC mentioned, if you check closely the errors are in the attached file and Unity also telling you the problems.
    For example the first error line is Assets/CustomLobbyController.cs(2,22); error CS10002: ; expected

    It means there is an error in the CustomLobbyController.cs file on the 2. row and 22. character. And the error code is CS10002, which is a ';' was left at the end of that line.

    If it is not a simple problem try to search for the error code, in this case for CS10002.

    But for now, here is a line from your code and a fix for it. Check the other errors like this and you will understand that there are missing characters.
    Code (CSharp):
    1. using Photon.Realtime
    2.  
    3. // It will compile
    4. using Photon.Realtime;
    One note for this, maybe the position (2,22) is not precise and you cannot see any error on that specific character, then it worth to check before / after a few characters and before / after one line, most of the errors are close to that position that the compiler mentions to you.
     
  4. UnitMC

    UnitMC

    Joined:
    Dec 13, 2020
    Posts:
    3




    THANK YOU!!
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,753