Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

JavaScript - Error BCE0018

Discussion in 'Scripting' started by vdubecky, Mar 7, 2016.

  1. vdubecky

    vdubecky

    Joined:
    Mar 4, 2016
    Posts:
    26
    Hello, I need advice.
    Please do you know why this script does not work? Can you help me please?
    Thank you

    Error
    "Assets/PlayerControl.js(10,25): BCE0018: The name 'InfoChar' does not denote a valid type ('not found'). Did you mean 'JetBrains.Annotations.InvokerParameterNameAttribute'?"

    Script -JavaScript
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. private var hasAxe : boolean = false;
    4.  
    5. private var canSwing : boolean = true;
    6. private var isSwinging : boolean = false;
    7. var swingTimer : float = 0.7;
    8.  
    9. private var controller : CharacterController;
    10. private var playerGUI : InfoChar;
    11.  
    12. function Start()
    13. {
    14.     hasAxe = true;
    15.     controller = GameObject.Find("First Person Controller").GetComponent(CharacterController);
    16.     playerGUI = GameObject.Find("First Person Controller").GetComponent(InfoChar);
    17. }
    18.  
    19. function Update()
    20. {
    21.     //If we aren't moving and if we aren't swinging, then we idle!
    22.  
    23.     if(controller.velocity.magnitude <= 0 && isSwinging == false)
    24.     {
    25.         GetComponent.<Animation>().Play("Idle");
    26.         GetComponent.<Animation>()["Idle"].wrapMode = WrapMode.Loop;
    27.         GetComponent.<Animation>()["Idle"].speed = 0.2;
    28.     }
    29.     //If we're holding shift and moving, then sprint!
    30.     if(controller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift))
    31.     {
    32.         GetComponent.<Animation>().Play("Sprint");
    33.         GetComponent.<Animation>()["Sprint"].wrapMode = WrapMode.Loop;
    34.     }
    35.     //WOODCUTTING SECTION
    36.     if(hasAxe == true && canSwing == true)
    37.     {
    38.         if(Input.GetMouseButtonDown(0))
    39.         {
    40.             //Stamina reduction applied to the PlayerGUI script
    41.             PlayerGUI.staminaBarDisplay -= 0.1;
    42.      
    43.             //Swinging animation
    44.             GetComponent.<Animation>().Play("Swing");
    45.             GetComponent.<Animation>()["Swing"].speed = 2;
    46.             isSwinging = true;
    47.             canSwing = false;
    48.         }
    49.     }
    50.     if(canSwing == false)
    51.     {
    52.         swingTimer -= Time.deltaTime;
    53.     }
    54.     if(swingTimer <= 0)
    55.     {
    56.         swingTimer = 1;
    57.         canSwing = true;
    58.         isSwinging = false;
    59.     }
    60.  
    61. }
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,777
    Can you paste the full text of the error, including the line number it points to?
     
  3. vdubecky

    vdubecky

    Joined:
    Mar 4, 2016
    Posts:
    26
    Yes, I'm sorry. Error is already there.
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,777
    There is no script named InfoChar that the compiler knows about. My guess is that there IS a script called InfoChar (because otherwise this would be too obvious), but it's a C# script - the JS compiler doesn't know about C# scripts except for certain cases. The best solution is basically to not mix JS and C# in the same project.
     
  5. vdubecky

    vdubecky

    Joined:
    Mar 4, 2016
    Posts:
    26
    OK thank you. Is it possible to change Java to C #? Thank you
     
  6. vdubecky

    vdubecky

    Joined:
    Mar 4, 2016
    Posts:
    26
    I used to convert the script. Script already goes where I want to move there, but does not perform what he has. It only reports the error in the game.
    Thank you
    Error
    NullReferenceException: Object reference not set to an instance of an object
    UnityStandardAssets.Characters.FirstPerson.PlayerControl.Update () (at Assets/PlayerControl.cs:37)



    New code - c#
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. namespace UnityStandardAssets.Characters.FirstPerson{
    5. public class PlayerControl : MonoBehaviour {
    6.  
    7.     private bool hasAxe = false;
    8.  
    9.     private bool canSwing = true;
    10.     private bool isSwinging = false;
    11.     public float swingTimer = 0.7f;
    12.  
    13.     private CharacterController controller ;
    14.     private InfoChar playerGUI;
    15.  
    16.     // Use this for initialization
    17.     void Start () {
    18.            
    19.             hasAxe = true;
    20.             //controller = GameObject.Find("First Person Controller").GetComponent(CharacterController);
    21.             //playerGUI = GameObject.Find("First Person Controller").GetComponent(PlayerGUI);
    22.  
    23.             controller = GameObject.FindGameObjectWithTag("Player").GetComponent ("CharacterController") as CharacterController; //I'm not shure if this is right but it's work perfect for me
    24.             playerGUI = GameObject.FindGameObjectWithTag("Player").GetComponent ("InfoChar") as InfoChar; //I'm not shure if this is right but it's work perfect for me
    25.     }
    26.    
    27.     // Update is called once per frame
    28.     void Update () {
    29.             //If we aren't moving and if we aren't swinging, then we idle!
    30.  
    31.             if(controller.velocity.magnitude <= 1 && isSwinging == false)
    32.             {
    33.                 GetComponent<Animation>().Play("Idle");
    34.                 GetComponent<Animation>()["Idle"].wrapMode = WrapMode.Loop;
    35.                 GetComponent<Animation>()["Idle"].speed = 0.2f;
    36.             }
    37.  
    38.             //If we're holding shift and moving, then sprint!
    39.  
    40.             if(controller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift))
    41.             {
    42.                 GetComponent<Animation>().Play("Sprint");
    43.                 GetComponent<Animation>()["Sprint"].wrapMode = WrapMode.Loop;
    44.             }
    45.  
    46.             //WOODCUTTING SECTION
    47.             if(hasAxe == true && canSwing == true)
    48.             {
    49.                 if(Input.GetMouseButtonDown(0))
    50.                 {
    51.                     //Stamina reduction applied to the PlayerGUI script
    52.                     playerGUI.staminaBarDisplay -= 0.1f;
    53.  
    54.                     //Swinging animation
    55.                     GetComponent<Animation>().Play("Swing");
    56.                     GetComponent<Animation>()["Swing"].speed = 2f;
    57.                     isSwinging = true;
    58.                     canSwing = false;
    59.                 }
    60.             }
    61.  
    62.             if(canSwing == false)
    63.             {
    64.                 swingTimer -= Time.deltaTime;
    65.             }
    66.  
    67.             if(swingTimer <= 0)
    68.             {
    69.                 swingTimer = 1;
    70.                 canSwing = true;
    71.                 isSwinging = false;
    72.             }
    73.         }
    74. }
    75. }
    76.  
     
  7. niresh_1

    niresh_1

    Joined:
    Mar 1, 2017
    Posts:
    1
    InfoChar ? Error!
    How to fix this? What to use instead of it?