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

BCE0005: Unknown identifier: 'playerPrefab'.

Discussion in 'Editor & General Support' started by EdgarCarrera, Jun 12, 2014.

  1. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    why i got this error??

    ERROR:
    Assets/Scripts/networking.js(160,48): BCE0005: Unknown identifier: 'playerPrefab'.


    Code (JavaScript):
    1. @script ExecuteInEditMode()
    2.  
    3. var gameName : String = "Mattsgamesfortesting";
    4.  
    5. var refreshing = false;
    6. var hostData : HostData[];
    7.  
    8. var create = false;
    9. var joining = false;
    10.  
    11. var serverName = "";
    12. var serverInfo = "";
    13. var serverPass = "";
    14.  
    15. var playerName = "";
    16.  
    17. var clientPass = "";
    18.  
    19. //var scrollPosition = "";
    20.  
    21. var scrollPosition : Vector2 = Vector2.zero;
    22.  
    23. function Start(){
    24.  
    25.     playerName = PlayerPrefs.GetString("Player Name");
    26. }
    27.  
    28. function OnGUI(){
    29.  
    30.     if(!Network.isClient && !Network.isServer){
    31.  
    32.         if(GUI.Button(Rect(Screen.width/2 - 50,Screen.height/2,100,20),"Create Game")){
    33.  
    34.             create = true;
    35.         }
    36.  
    37.         if(GUI.Button(Rect(Screen.width/2 - 50,Screen.height/2 + 30,100,20),"Create Game")){
    38.  
    39.             joining = true;
    40.             refreshHostList();
    41.         }
    42.     }
    43.  
    44. if(create){
    45.  
    46.     if(GUI.Button(Rect(Screen.wigth/2 - 50,Screen.height/3 + 110,100,50),"Create")){
    47.  
    48.         startServer();
    49.     }
    50.  
    51.     GUI.Label(Rect(Screen.width/2 - 110,Screen.height/3,100,20),"Server Name:");
    52.     GUI.Label(Rect(Screen.width/2 + 40,Screen.height/3,100,20),"Password:");
    53.     GUI.Label(Rect(Screen.width/2 - 30,Screen.height/3 + 90,100,20),"Server Info:");
    54.  
    55.     serverName = GUI.TextField (Rect(Screen.width/2 - 120,Screen.height/3 + 30, 100, 20),serverName, 12);
    56.     serverPass = GUI.PasswordField (Rect(Screen.width/2 + 20,Screen.height/3 + 30, 100, 20),serverPass, "*"[0], 12);
    57.     serverInfo = GUI.TextField (Rect(Screen.width/2 - 70,Screen.height/3 + 30, 150, 20),serverInfo, 12);
    58.  
    59.     if(GUI.Button(Rect(Screen.width/1.2,Screen.height/20,100,20),"Back")){
    60.  
    61.         create = false;
    62.     }
    63.  
    64.     if(joining){
    65.  
    66.         if(hostData){
    67.  
    68.             scrollPosition = GUI.BeginScrollView (Rect(Screen.width/4,Screen.height/6,Screen.width/1.5,Screen.height/2),scrollPosition, Rect(0, 0, 300, 1000/*hostData.Length * 30*/));
    69.        
    70.             GUI.Label(Rect(30,0,100,20),"Game Name");
    71.             GUI.Label(Rect(350,0,100,20),"Server Info");
    72.             GUI.Label(Rect(590,0,100,20),"Player Count");
    73.             GUI.Label(Rect(700,0,100,20),"Password");
    74.  
    75.             for (var i:int = 0; i < hostData.length; i++){
    76.  
    77.                 GUI.Label(Rect(0,30 + i * 30,200,22),hostData[i].gameName);
    78.                 GUI.Label(Rect(160,30 + i * 30,500,22),hostData[i].comment);
    79.                 GUI.Label(Rect(640,30 + i * 30,100,22),hostData[i].connectedPlayers + " / " + hostData[i].playerLimit);
    80.  
    81.                 if(hostData[i].passwordProtected){
    82.  
    83.                     clientPass = GUI.PasswordField(Rect(680, 30 + i * 30, 100, 25), clientPass, "*"[0], 12);
    84.                 }
    85.  
    86.                 if(GUI.Button(Rect(800, 30 + i * 30, 100, 25), "Join")){
    87.                
    88.                     Network.Connect(hostData[i], clientPass);
    89.                 }
    90.             }
    91.             GUI.EndScrollView();
    92.         }
    93.  
    94.         if(!hostData){
    95.  
    96.             GUI.Label(Rect(Screen.width/2 - 50,Screen.height/3,200,25), "No Games Found");
    97.  
    98.             if(GUI.Button(Rect(Screen.width/2 - 50,Screen.height/3 + 30,105,25),"Refresh")){
    99.                 refreshHostList();
    100.             }
    101.         }
    102.    
    103.         if(GUI.Button(Rect(Screen.width/1.2,Screen.height/20,100,20),"Back")){
    104.  
    105.             joining = false;
    106.         }
    107.     }
    108.  
    109.         if(GUI.Button(Rect(Screen.width/20,Screen.height/20,100,20),"Quit")){
    110.  
    111.             Application.Quit();
    112.         }
    113.  
    114.         GUI.Label(Rect(Screen.width/2 - 35,Screen.height/1.2 - 30,100,20),"Your Name:");
    115.         playerName = GUI.TextField(Rect(Screen.width/2 - 50,Screen.height/1.2,100,20), playerName, 12);
    116.         }
    117.     }
    118.  
    119.     function Update (){
    120.  
    121.         if(refreshing){
    122.  
    123.             if(MasterServer.PollHostList().Length > 0){
    124.  
    125.                 refreshing = false;
    126.                 hostData = MasterServer.PollHostList();
    127.             }
    128.         }
    129.     }
    130.  
    131.     function startServer(){
    132.  
    133.         if(serverPass != ""){
    134.  
    135.             Network.incomingPassword = serverPass;
    136.         }
    137.  
    138.         Network.InitializedServer(15,25001, !Network.HavePublicAddress);
    139.         MasterServer.RegisterHost(gameName,serverInfo);
    140.     }
    141.  
    142.     function OnServerInitialized(){
    143.  
    144.         DontDestroyOnLoad(transform.gameObject);
    145.  
    146.         Application.LoadLevel ("Lobby");
    147.  
    148.         lobbySpawn();
    149.     }
    150.  
    151.     function OnConnectedToServer(){
    152.  
    153.         lobbySpawn();
    154.     }
    155.  
    156.     function lobbySpawn(){
    157.  
    158.         yield WaitForSeconds(0.1);
    159.  
    160.         var made = Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
    161.  
    162.         made.GetComponent(playerMove).playerName = playerName;
    163.  
    164.         PlayerPrefs.SetString("Player Name", playerName);
    165.  
    166.         if(Network.isClient){
    167.  
    168.             Destroy(this);
    169.         }
    170.     }
    171.  
    172.     function refreshHostList(){
    173.  
    174.         MasterServer.ClearHostList();
    175.         MasterServer.RequestHostList(gameName);
    176.         refreshing = true;
    177.     }
     
  2. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    You don't seem to have playerPrefab defined anywhere in your code. I'm guessing your intent is to add a field to your script with that name and set it from the inspector.
     
  3. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    but this is one error?
     
  4. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    Yes, that is one error. Are you seeing more?
     
  5. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    yes look..

    Errors:

    *Assets/Scripts/networkView.js(7,30): BCE0005: Unknown identifier: 'MouseLook'.
    *Assets/Scripts/playerMove.js(9,47): BCE0019: 'AllBuffered' is not a member of 'UnityEngine.RPC'.
    *Assets/Scripts/playerMove.js(14,44): BCE0019: 'AllBuffered' is not a member of 'UnityEngine.RPC'.
    *Assets/Scripts/playerMove.js(19,44): BCE0019: 'AllBuffered' is not a member of 'UnityEngine.RPC'.
    *Assets/Scripts/playerMove.js(24,45): BCE0019: 'AllBuffered' is not a member of 'UnityEngine.RPC'.
    *Assets/Scripts/networking.js(160,48): BCE0005: Unknown identifier: 'playerPrefab'

    My 3 Script.

    networking.js

    Code (JavaScript):
    1. @script ExecuteInEditMode()
    2.  
    3. var gameName : String = "Mattsgamesfortesting";
    4.  
    5. var refreshing = false;
    6. var hostData : HostData[];
    7.  
    8. var create = false;
    9. var joining = false;
    10.  
    11. var serverName = "";
    12. var serverInfo = "";
    13. var serverPass = "";
    14.  
    15. var playerName = "";
    16.  
    17. var clientPass = "";
    18.  
    19. //var scrollPosition = "";
    20.  
    21. var scrollPosition : Vector2 = Vector2.zero;
    22.  
    23. function Start(){
    24.  
    25.     playerName = PlayerPrefs.GetString("Player Name");
    26. }
    27.  
    28. function OnGUI(){
    29.  
    30.     if(!Network.isClient && !Network.isServer){
    31.  
    32.         if(GUI.Button(Rect(Screen.width/2 - 50,Screen.height/2,100,20),"Create Game")){
    33.  
    34.             create = true;
    35.         }
    36.  
    37.         if(GUI.Button(Rect(Screen.width/2 - 50,Screen.height/2 + 30,100,20),"Create Game")){
    38.  
    39.             joining = true;
    40.             refreshHostList();
    41.         }
    42.     }
    43.  
    44. if(create){
    45.  
    46.     if(GUI.Button(Rect(Screen.wigth/2 - 50,Screen.height/3 + 110,100,50),"Create")){
    47.  
    48.         startServer();
    49.     }
    50.  
    51.     GUI.Label(Rect(Screen.width/2 - 110,Screen.height/3,100,20),"Server Name:");
    52.     GUI.Label(Rect(Screen.width/2 + 40,Screen.height/3,100,20),"Password:");
    53.     GUI.Label(Rect(Screen.width/2 - 30,Screen.height/3 + 90,100,20),"Server Info:");
    54.  
    55.     serverName = GUI.TextField (Rect(Screen.width/2 - 120,Screen.height/3 + 30, 100, 20),serverName, 12);
    56.     serverPass = GUI.PasswordField (Rect(Screen.width/2 + 20,Screen.height/3 + 30, 100, 20),serverPass, "*"[0], 12);
    57.     serverInfo = GUI.TextField (Rect(Screen.width/2 - 70,Screen.height/3 + 30, 150, 20),serverInfo, 12);
    58.  
    59.     if(GUI.Button(Rect(Screen.width/1.2,Screen.height/20,100,20),"Back")){
    60.  
    61.         create = false;
    62.     }
    63.  
    64.     if(joining){
    65.  
    66.         if(hostData){
    67.  
    68.             scrollPosition = GUI.BeginScrollView (Rect(Screen.width/4,Screen.height/6,Screen.width/1.5,Screen.height/2),scrollPosition, Rect(0, 0, 300, 1000/*hostData.Length * 30*/));
    69.            
    70.             GUI.Label(Rect(30,0,100,20),"Game Name");
    71.             GUI.Label(Rect(350,0,100,20),"Server Info");
    72.             GUI.Label(Rect(590,0,100,20),"Player Count");
    73.             GUI.Label(Rect(700,0,100,20),"Password");
    74.  
    75.             for (var i:int = 0; i < hostData.length; i++){
    76.  
    77.                 GUI.Label(Rect(0,30 + i * 30,200,22),hostData[i].gameName);
    78.                 GUI.Label(Rect(160,30 + i * 30,500,22),hostData[i].comment);
    79.                 GUI.Label(Rect(640,30 + i * 30,100,22),hostData[i].connectedPlayers + " / " + hostData[i].playerLimit);
    80.  
    81.                 if(hostData[i].passwordProtected){
    82.  
    83.                     clientPass = GUI.PasswordField(Rect(680, 30 + i * 30, 100, 25), clientPass, "*"[0], 12);
    84.                 }
    85.  
    86.                 if(GUI.Button(Rect(800, 30 + i * 30, 100, 25), "Join")){
    87.                    
    88.                     Network.Connect(hostData[i], clientPass);
    89.                 }
    90.             }
    91.             GUI.EndScrollView();
    92.         }
    93.  
    94.         if(!hostData){
    95.  
    96.             GUI.Label(Rect(Screen.width/2 - 50,Screen.height/3,200,25), "No Games Found");
    97.  
    98.             if(GUI.Button(Rect(Screen.width/2 - 50,Screen.height/3 + 30,105,25),"Refresh")){
    99.                 refreshHostList();
    100.             }
    101.         }
    102.        
    103.         if(GUI.Button(Rect(Screen.width/1.2,Screen.height/20,100,20),"Back")){
    104.  
    105.             joining = false;
    106.         }
    107.     }
    108.  
    109.         if(GUI.Button(Rect(Screen.width/20,Screen.height/20,100,20),"Quit")){
    110.  
    111.             Application.Quit();
    112.         }
    113.  
    114.         GUI.Label(Rect(Screen.width/2 - 35,Screen.height/1.2 - 30,100,20),"Your Name:");
    115.         playerName = GUI.TextField(Rect(Screen.width/2 - 50,Screen.height/1.2,100,20), playerName, 12);
    116.         }
    117.     }
    118.  
    119.     function Update (){
    120.  
    121.         if(refreshing){
    122.  
    123.             if(MasterServer.PollHostList().Length > 0){
    124.  
    125.                 refreshing = false;
    126.                 hostData = MasterServer.PollHostList();
    127.             }
    128.         }
    129.     }
    130.  
    131.     function startServer(){
    132.  
    133.         if(serverPass != ""){
    134.  
    135.             Network.incomingPassword = serverPass;
    136.         }
    137.  
    138.         Network.InitializedServer(15,25001, !Network.HavePublicAddress);
    139.         MasterServer.RegisterHost(gameName,serverInfo);
    140.     }
    141.  
    142.     function OnServerInitialized(){
    143.  
    144.         DontDestroyOnLoad(transform.gameObject);
    145.  
    146.         Application.LoadLevel ("Lobby");
    147.  
    148.         lobbySpawn();
    149.     }
    150.  
    151.     function OnConnectedToServer(){
    152.  
    153.         lobbySpawn();
    154.     }
    155.    
    156.     function lobbySpawn(){
    157.  
    158.         yield WaitForSeconds(0.1);
    159.  
    160.         var made = Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
    161.  
    162.         made.GetComponent(playerMove).playerName = playerName;
    163.  
    164.         PlayerPrefs.SetString("Player Name", playerName);
    165.  
    166.         if(Network.isClient){
    167.  
    168.             Destroy(this);
    169.         }
    170.     }
    171.  
    172.     function refreshHostList(){
    173.  
    174.         MasterServer.ClearHostList();
    175.         MasterServer.RequestHostList(gameName);
    176.         refreshing = true;
    177.     }
    networkView.js

    Code (JavaScript):
    1. function Awake() {
    2.  
    3.     if(!networkView.isMine){
    4.  
    5.         GetComponentInChildren(Camera).enabled = false;
    6.  
    7.         GetComponent(MouseLook).enabled = false;
    8.  
    9.         GetComponent(playerMove).enabled = false;
    10.     }
    11. }
    playerMove.js

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var playerName : String;
    4.  
    5. function Update () {
    6.  
    7.     if(Input.GetButton("w")){
    8.  
    9.         networkView.RPC("forward",RPC.AllBuffered);
    10.     }
    11.    
    12.     if(Input.GetButton("a")){
    13.  
    14.         networkView.RPC("left",RPC.AllBuffered);
    15.     }
    16.    
    17.     if(Input.GetButton("s")){
    18.  
    19.         networkView.RPC("back",RPC.AllBuffered);
    20.     }
    21.    
    22.     if(Input.GetButton("d")){
    23.  
    24.         networkView.RPC("right",RPC.AllBuffered);
    25.     }
    26. }
    27.  
    28. function OnGUI(){
    29.  
    30.     GUI.Label(Rect(Screen.width/2,Screen.height/2,100,20),"X");
    31. }
    32.  
    33. @RPC
    34. function forward(){
    35.  
    36.     transform.Translate(Vector3.forward / 10);
    37. }
    38.  
    39. @RPC
    40. function left(){
    41.  
    42.     transform.Translate(Vector3.left / 10);
    43. }
    44.  
    45. @RPC
    46. function back(){
    47.  
    48.     transform.Translate(Vector3.back / 10);
    49. }
    50.  
    51. @RPC
    52. function right(){
    53.  
    54.     transform.Translate(Vector3.right / 10);
    55. }
    56.  
     
  6. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
  7. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    I'm not sure how anyone was supposed to divine that you had other errors without you mentioning them at first or even bothering to include the code in your original post.

    Replace RPC.AllBuffered with RPCMode.AllBuffered. And do you even have a script in your project named "MouseLook"? Because you won't be able to GetComponent on it if you don't have it defined somewhere.

    In all honesty, if you're having this much trouble fixing a simple compiler error, then I would hold off jumping into networking until the I have had a better grasp of the basics if I were you.
     
  8. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Please don't bump your thread. If no one replies it means your question is too vague. So, instead of just bumping, write more words that helps explain what's going on. So, for example, in the 4 hours between posting and bumping, presumably you did some detective work. Telling the community what you've tried is good form.