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

Error that isnt an error [javascript]

Discussion in 'Scripting' started by Stephen7755, Apr 29, 2014.

  1. Stephen7755

    Stephen7755

    Joined:
    Apr 29, 2014
    Posts:
    4
    Im making a game like minecraft and it throws an error that i know isnt one.. code below.. error marked with an arrow.. PLS HELP

    Error :

    Assets/scripts/BlockMaker.js(22,27): BCE0043: Unexpected token: -=.

    Code (Its long):

    Code (csharp):
    1. #pragma strict
    2.  
    3.  
    4. var GrassBlock : Transform;
    5. var StoneBlock : Transform;
    6. var BlockSeleted : float = 1;
    7. var Range : float = 20;
    8.  
    9. function Start () {
    10.  
    11. }
    12.  
    13. function Update ()
    14. {
    15.  
    16. var BlockSeleted : float = 1;
    17. var Range : float = 20;
    18.  
    19.  
    20. if (Input.GetKeyDown(KeyCode.Q))
    21.     {
    22.         var BlockSelected -= 1;  <------- HERES THE ERROR
    23.     }
    24.  
    25. if (Input.GetKeyDown(KeyCode.E))
    26.     {
    27.         var BlockSelected += 1;
    28.     }
    29.  
    30. if(Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
    31.     {
    32.         var Hit : RaycastHit;
    33.         var LookingDirection = transform.TransformDirection(Vector3.forward);
    34.  
    35.         if(Physics.Raycast(transform.position, LookingDirection, Hit, 20))
    36.         {
    37.         if (Input.GetMouseButtonDown(1))
    38.         {
    39.         if(var BlockSelected ==1)
    40.         {
    41.         var GrassBlock : Transform = Instantiate (GrassBlock, Hit.collider.transform.position + Hit.normal.normalized, Quaternion.identity);
    42.         GrassBlock.tag = "GrassBlock";
    43.         }
    44.        
    45.  
    46.         if(var BlockSelected ==2)
    47.         {
    48.         var StoneBlock : Transform = Instantiate (StoneBlock, Hit.collider.transform.position + Hit.normal.normalized, Quaternion.identity);
    49.         GrassBlock.tag = "StoneBlock";
    50.         }
    51.         }
    52.     }
    53.  
    54.     else
    55.     {
    56.     Destroy(Hit.transform.gameObject);
    57.     }
    58.  
    59. }
    60.  
    61.  
    62.  
    63.  
    64.  
    65.  
    66. }
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    It is expecting an initialisation i guess, due to the keyword 'var'. Try to remove it.
    Same happens few more times in your code.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    It's totally an error. You can't use -= or += when declaring variables, and in fact you don't want to declare variables there at all. Some additional things: I seriously doubt you want to use floats for that, and it's easier to read the code if you stick with the convention of using lowercase for variable names; uppercase is for classes and functions.

    --Eric
     
  4. Dameon_

    Dameon_

    Joined:
    Apr 11, 2014
    Posts:
    542
    You misspelled BlockSelected as BlockSeleted on line 6.
     
  5. Stephen7755

    Stephen7755

    Joined:
    Apr 29, 2014
    Posts:
    4
    Fixed it! Thanks!
     
  6. Stephen7755

    Stephen7755

    Joined:
    Apr 29, 2014
    Posts:
    4
    I caught that when fixing it... thanks tho!
     
  7. Stephen7755

    Stephen7755

    Joined:
    Apr 29, 2014
    Posts:
    4
    I had them declared at the top, but when i removed var, it fixed it.. i made all my variables lowercase too :D.. thanks!