Search Unity

Scripting problem?

Discussion in 'Scripting' started by edplane, Jul 13, 2009.

  1. edplane

    edplane

    Joined:
    Jul 13, 2009
    Posts:
    485
    Hi, im new to unity, and made my first script to open a lock door in a game im making recreating Half-Life,

    Code (csharp):
    1.  
    2. function Update () {
    3.    
    4.     Time.time = 6;
    5.     var translation = Time.deltaTime * 3.6;
    6.     Right lock transform.Translate (-0.2566914, 1.129246, translation);
    7.     var translation = Time.deltaTime * -3.6
    8.     Left lock transform.Translate (-0.260433, 1.103976, translation);
    9.     Time.time = 2;
    10.     var translation = Time.deltaTime * 3.6;
    11.     Top door transform.Translate (0.1311612, 1.930578, translation);
    12.     var translation = Time.deltaTime * -3.6
    13.     Bottom door transform.Translate (0.1311612, 0.03431386, translation);
    14.    
    15.     }
    but when i try to add it to the prefab, the console says:
    • Assets/Standard Assets/Scripts/Door open.js(6,14): UCE0001: ';' expected. Insert a semicolon at the end. (Filename: Assets/Standard Assets/Scripts/Door open.js Line: 6)
      Assets/Standard Assets/Scripts/Door open.js(6,19): UCE0001: ';' expected. Insert a semicolon at the end. (Filename: Assets/Standard Assets/Scripts/Door open.js Line: 6)
      Assets/Standard Assets/Scripts/Door open.js(7,48): UCE0001: ';' expected. Insert a semicolon at the end. (Filename: Assets/Standard Assets/Scripts/Door open.js Line: 7)
      Assets/Standard Assets/Scripts/Door open.js(8,13): UCE0001: ';' expected. Insert a semicolon at the end. (Filename: Assets/Standard Assets/Scripts/Door open.js Line: 8)
      Assets/Standard Assets/Scripts/Door open.js(8,18): UCE0001: ';' expected. Insert a semicolon at the end. (Filename: Assets/Standard Assets/Scripts/Door open.js Line: 8)
      Assets/Standard Assets/Scripts/Door open.js(11,12): UCE0001: ';' expected. Insert a semicolon at the end. (Filename: Assets/Standard Assets/Scripts/Door open.js Line: 11)
      Assets/Standard Assets/Scripts/Door open.js(11,17): UCE0001: ';' expected. Insert a semicolon at the end. (Filename: Assets/Standard Assets/Scripts/Door open.js Line: 11)
      Assets/Standard Assets/Scripts/Door open.js(12,48): UCE0001: ';' expected. Insert a semicolon at the end. (Filename: Assets/Standard Assets/Scripts/Door open.js Line: 12)
      Assets/Standard Assets/Scripts/Door open.js(13,15): UCE0001: ';' expected. Insert a semicolon at the end. (Filename: Assets/Standard Assets/Scripts/Door open.js Line: 13)
      Assets/Standard Assets/Scripts/Door open.js(13,20): UCE0001: ';' expected. Insert a semicolon at the end. (Filename: Assets/Standard Assets/Scripts/Door open.js Line: 13)

    as you see, i do have a simicolin at the end of the lines! What do i do? :?
     
  2. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    347
    What's with those "Right lock ", "Left lock " etc? That doesn't look like correct syntax to me. In JavaScript, whitespace is ignored and elements separated by comma (lists, parameters) or dots (objects).

    Also, two lines are really missing the semicolon at the end. Sometimes, errors at one place can cause errors at other places so it's best to fix them one by one.
     
  3. Apache

    Apache

    Joined:
    Sep 26, 2008
    Posts:
    134
    There's an error: Time.time is read only so you can't assign it a value.

    To make a control to the time passed you need to use:
    Code (csharp):
    1. float startTime;
    2.  
    3. void Start () {
    4.    startTime = Time.time;
    5. } // Start
    6.  
    7. void Update () {
    8.    float passedTime = Time.time - startTime;
    9. } // Update
    but note that these instructions and also Time.deltaTime are Time.timeScale pending so if you change the timeScale (for example reducing it to emphatize a situation) also the time passed is "scaled" so your animation will be slower.

    Now I have to ask you something: what are "Right lock transform", "Left lock transform", "Top door transform" and "Bottom door transform"? If they are variable you CANNOT name them with space so maybe you meant, for example "LeftLockTransform" if this is a var of Transform type or "LeftLock.transform" if it is a variable of GameObject type.

    Try to fix your code and then we can go on !!! ;)
     
  4. LucidMovement

    LucidMovement

    Joined:
    Jun 11, 2009
    Posts:
    14
    You probably already caught this but on the off chance you are still having an issue with it. At the end of two of your lines you are missing semicolons.

    Toss a semicolon and the end and with the changes suggested by Apache you should be good to go.