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 I need help fixing this!

Discussion in 'Scripting' started by TwoTeraBytes, Dec 16, 2020.

  1. TwoTeraBytes

    TwoTeraBytes

    Joined:
    Oct 8, 2020
    Posts:
    14
    I have been working on this project for hours and i went to this error that i not seen before:
    Here is the error:
    Assets\MFPS\Scripts\Network\FriendList\bl_FriendList.cs(27,5): error CS1519: Invalid token 'void' in class, struct, or interface member declaration

    Here is the code:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections.Generic;
    4. using Photon.Pun;
    5. using Photon.Realtime;
    6. using System.Collections;
    7. using UnityEngine.Networking;
    8.  
    9. public class bl_FriendList : bl_PhotonHelper, IMatchmakingCallbacks, IConnectionCallbacks, ILobbyCallbacks
    10. {
    11.     [HideInInspector]
    12.     public List<string> Friends = new List<string>();
    13.  
    14.     public const string FriendSaveKey = "LSFriendList";
    15.     private char splitChar = '/';
    16.  
    17.     [HideInInspector] public bool WaitForEvent = false;
    18.     private bl_FriendListUI FriendUI;
    19.     [HideInInspector]public List<FriendInfo> FriendList = new List<FriendInfo>();
    20. #if ULSP
    21.     private bl_DataBase
    22. #endif
    23.  
    24.     /// <summary>
    25.     ///
    26.     /// </summary>
    27.     void Awake()
    28.     {
    29.         FriendUI = bl_LobbyUI.Instance.FriendUI;
    30.         PhotonNetwork.AddCallbackTarget(this);
    31. #if ULSP
    32.         DataBase = bl_DataBase.Instance;
    33. #endif
    34.         if (PhotonNetwork.IsConnected)
    35.         {
    36.             GetFriendsStore();
    37.             InvokeRepeating("UpdateList", 1, 1);
    38.         }
    39.     }
    40.  
    41.     void OnDisable()
    42.     {
    43.         PhotonNetwork.RemoveCallbackTarget(this);
    44.     }
    45.  
    46.     /// <summary>
    47.     ///
    48.     /// </summary>
    49.     void GetFriendsStore()
    50.     {
    51.         if (!PhotonNetwork.IsConnectedAndReady || !PhotonNetwork.InLobby)
    52.             return;
    53.         //Get all friends saved
    54. #if ULSP
    55.         if(DataBase != null)
    56.         {
    57.             Friends.AddRange(DataBase.LocalUser.FriendList.ToArray());
    58.         }
    59.         else
    60.         {
    61.             string cacheFriend = PlayerPrefs.GetString(SaveKey, "Null");
    62.             if (!string.IsNullOrEmpty(cacheFriend))
    63.             {
    64.                 string[] splitFriends = cacheFriend.Split(splitChar);
    65.                 Friends.AddRange(splitFriends);
    66.             }
    67.         }
    68. #else
    69.         string cacheFriend = PlayerPrefs.GetString(SaveKey, "Null");
    70.         if (!string.IsNullOrEmpty(cacheFriend))
    71.         {
    72.             string[] splitFriends = cacheFriend.Split(splitChar);
    73.             Friends.AddRange(splitFriends);
    74.         }
    75. #endif
    76.         //Find all friends names in photon list.
    77.         if (Friends.Count > 0)
    78.         {
    79.             PhotonNetwork.FindFriends(Friends.ToArray());
    80.             //Update the list UI
    81.             FriendUI.UpdateFriendList(true);
    82.         }
    83.         else
    84.         {
    85.            // Debug.Log("No friends saved");
    86.             return;
    87.         }
    88.     }
    89.  
    90.     /// <summary>
    91.     /// Call For Update List of friends.
    92.     /// </summary>
    93.     void UpdateList()
    94.     {
    95.         if (!PhotonNetwork.IsConnected  || PhotonNetwork.InRoom)
    96.             return;
    97.  
    98.         if (Friends.Count > 0)
    99.         {
    100.             if (Friends.Count > 1 && Friends.Contains("Null"))
    101.             {
    102.                 Friends.Remove("Null");
    103.                 Friends.Remove("Null");
    104.                 SaveFriends();
    105.             }
    106.             if (PhotonNetwork.IsConnectedAndReady && Friends.Count > 0)
    107.             {
    108.                 PhotonNetwork.FindFriends(Friends.ToArray());
    109.             }
    110.         }
    111.     }
    112.  
    113.     /// <summary>
    114.     ///
    115.     /// </summary>
    116.     public void SaveFriends()
    117.     {
    118.         string allfriends = string.Join(splitChar.ToString(), Friends.ToArray());
    119. #if ULSP
    120.         if(DataBase != null && !DataBase.isGuest)
    121.         {
    122.             StartCoroutine(SaveInDataBase(allfriends));
    123.         }
    124.         else
    125.         {
    126.             PlayerPrefs.SetString(SaveKey, allfriends);
    127.         }
    128. #else
    129.          PlayerPrefs.SetString(SaveKey, allfriends);
    130. #endif
    131.     }
    132.  
    133. #if ULSP
    134.     IEnumerator SaveInDataBase(string line)
    135.     {
    136.         WWWForm wf = new WWWForm();
    137.         string hash = bl_DataBaseUtils.Md5Sum(DataBase.LocalUser.LoginName + bl_LoginProDataBase.Instance.SecretKey).ToLower();
    138.         wf.AddField("name", DataBase.LocalUser.LoginName);
    139.         wf.AddField("flist", line);
    140.         wf.AddField("typ", 5);
    141.         wf.AddField("hash", hash);
    142.  
    143.         using (UnityWebRequest www = UnityWebRequest.Post(bl_LoginProDataBase.Instance.GetUrl(bl_LoginProDataBase.URLType.DataBase), wf))
    144.         {
    145.             yield return www.SendWebRequest();
    146.  
    147.             if (!www.isNetworkError)
    148.             {
    149.                 if (www.downloadHandler.text.Contains("save"))
    150.                 {
    151.                     Debug.Log("Friend list save in database!");
    152.                     DataBase.LocalUser.SetFriends(line);
    153.                 }
    154.                 else
    155.                 {
    156.                     Debug.Log(www.downloadHandler.text);
    157.                 }
    158.             }
    159.             else
    160.             {
    161.                 Debug.LogError(www.error);
    162.             }
    163.         }
    164.     }
    165. #endif
    166.  
    167.     /// <summary>
    168.     ///
    169.     /// </summary>
    170.     /// <param name="field"></param>
    171.     public void AddFriend(InputField field)
    172.     {
    173.         if(Friends.Count > bl_GameData.Instance.MaxFriendsAdded)
    174.         {
    175.             FriendUI.ShowLog("Max friends reached!");
    176.             return;
    177.         }
    178.         string t = field.text;
    179.         if (string.IsNullOrEmpty(t))
    180.             return;
    181.  
    182.         if(FriendUI != null && FriendUI.hasThisFriend(t))
    183.         {
    184.             FriendUI.ShowLog("Already has added this friend.");
    185.             return;
    186.         }
    187.         if(t == PhotonNetwork.NickName)
    188.         {
    189.             FriendUI.ShowLog("You can't add yourself.");
    190.             return;
    191.         }
    192.  
    193.         Friends.Add(t);
    194.         PhotonNetwork.FindFriends(Friends.ToArray());
    195.         FriendUI.UpdateFriendList(true);
    196.         SaveFriends();
    197.         WaitForEvent = true;
    198.  
    199.         field.text = string.Empty;
    200.     }
    201.  
    202.     /// <summary>
    203.     ///
    204.     /// </summary>
    205.     /// <param name="field"></param>
    206.     public void AddFriend(string friend)
    207.     {
    208.         if (Friends.Contains(friend)) return;
    209.  
    210.         Friends.Add(friend);
    211.         PhotonNetwork.FindFriends(Friends.ToArray());
    212.         FriendUI.UpdateFriendList(true);
    213.         SaveFriends();
    214.         WaitForEvent = true;
    215.     }
    216.  
    217.     /// <summary>
    218.     ///
    219.     /// </summary>
    220.     /// <param name="friend"></param>
    221.     public void RemoveFriend(string friend)
    222.     {
    223.         if (Friends.Contains(friend))
    224.         {
    225.             Friends.Remove(friend);
    226.             SaveFriends();
    227.             if (Friends.Count > 0)
    228.             {
    229.                 if(Friends.Count > 1 && Friends.Contains("Null"))
    230.                 {
    231.                     Friends.Remove("Null");
    232.                     Friends.Remove("Null");
    233.                     SaveFriends();
    234.                 }
    235.                 if(Friends.Count > 0)
    236.                 PhotonNetwork.FindFriends(Friends.ToArray());
    237.             }
    238.             else
    239.             {
    240.                 AddFriend("Null");
    241.                 if (Friends.Count > 0)
    242.                     PhotonNetwork.FindFriends(Friends.ToArray());
    243.             }
    244.  
    245.             FriendUI.UpdateFriendList(true);
    246.             WaitForEvent = true;
    247.         }
    248.         else { Debug.Log("This user doesn't exist"); }
    249.     }
    250.  
    251.     /// <summary>
    252.     /// custom key for each player can save multiple friend list in a same device.
    253.     /// </summary>
    254.     private string SaveKey
    255.     {
    256.         get
    257.         {
    258.             return PhotonNetwork.NickName + FriendSaveKey;
    259.         }
    260.     }
    261.  
    262.     public bool haveFriendsSlots { get { return Friends.Count < bl_GameData.Instance.MaxFriendsAdded; } }
    263.     public bool haveThisPlayerAsFriend(string playerName) { return Friends.Contains(playerName); }
    264.  
    265.     bool firstBuild = false;
    266.     public void OnFriendListUpdate(List<FriendInfo> friendList)
    267.     {
    268.         bool build = (friendList.Count != FriendList.Count);
    269.         if (friendList.Count == 1)
    270.         {
    271.             if (friendList[0].UserId != "Null")
    272.             {
    273.                 if (!firstBuild) { build = true; firstBuild = true; }
    274.             }
    275.             else firstBuild = false;
    276.          
    277.         }
    278.         else firstBuild = false;
    279.  
    280.         FriendList = friendList;
    281.         UpdateList();
    282.         FriendUI.UpdateFriendList(build);
    283.     }
    284.  
    285.     public void OnCreatedRoom()
    286.     {
    287.  
    288.     }
    289.  
    290.     public void OnCreateRoomFailed(short returnCode, string message)
    291.     {
    292.  
    293.     }
    294.  
    295.     public void OnJoinRoomFailed(short returnCode, string message)
    296.     {
    297.  
    298.     }
    299.  
    300.     public void OnJoinRandomFailed(short returnCode, string message)
    301.     {
    302.  
    303.     }
    304.  
    305.     public void OnLeftRoom()
    306.     {
    307.  
    308.     }
    309.  
    310.     public void OnJoinedRoom()
    311.     {
    312.         CancelInvoke("UpdateList");
    313.     }
    314.  
    315.     public void OnConnected()
    316.     {
    317.      
    318.     }
    319.  
    320.     public void OnConnectedToMaster()
    321.     {
    322.  
    323.     }
    324.  
    325.     public void OnJoinedLobby()
    326.     {
    327.         GetFriendsStore();
    328.         InvokeRepeating("UpdateList", 1, 1);
    329.         FriendUI.Panel.SetActive(true);
    330.     }
    331.  
    332.     public void OnDisconnected(DisconnectCause cause)
    333.     {
    334.         CancelInvoke("UpdateList");
    335.     }
    336.  
    337.     public void OnRegionListReceived(RegionHandler regionHandler)
    338.     {
    339.      
    340.     }
    341.  
    342.     public void OnCustomAuthenticationResponse(Dictionary<string, object> data)
    343.     {
    344.      
    345.     }
    346.  
    347.     public void OnCustomAuthenticationFailed(string debugMessage)
    348.     {
    349.      
    350.     }
    351.  
    352.     public void OnLeftLobby()
    353.     {
    354.      
    355.     }
    356.  
    357.     public void OnRoomListUpdate(List<RoomInfo> roomList)
    358.     {
    359.      
    360.     }
    361.  
    362.     public void OnLobbyStatisticsUpdate(List<TypedLobbyInfo> lobbyStatistics)
    363.     {
    364.      
    365.     }
    366.  
    367.     private static bl_FriendList _instance;
    368.     public static bl_FriendList Instance
    369.     {
    370.         get
    371.         {
    372.             if (_instance == null)
    373.             {
    374.                 _instance = FindObjectOfType<bl_FriendList>();
    375.             }
    376.             return _instance;
    377.         }
    378.     }
    379. }
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,992
    check line 21?
     
    PraetorBlue likes this.
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    You haven't finished the variable declaration on line 21:
    Code (CSharp):
    1.     private bl_DataBase
    2. #endif
    3.     /// <summary>
    4.     ///
    5.     /// </summary>
    6.     void Awake()
     
  4. TwoTeraBytes

    TwoTeraBytes

    Joined:
    Oct 8, 2020
    Posts:
    14
    I think i fixed it thanks