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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

strainge error

Discussion in 'Scripting' started by RankXenon, Jun 4, 2013.

  1. RankXenon

    RankXenon

    Joined:
    Jan 20, 2013
    Posts:
    48
    Sorry if i failed on a stupid thing, i am getting a error :

    1.(9,22) expecting ), found "=".
    2.(9,24) unexpected token: 1.
    3.(10,27) expecting :, found ";".

    i tried to resolve this error but i don't understand what is wrong in the script :(
    Code (csharp):
    1. var RandomPos:float;
    2.  
    3. InvokeRepeating("RandomPosFunc",0,2);
    4.  
    5. function RandomPosFunc () {
    6.     RandomPos=Random.Range(1,5);
    7. }
    8. function Update () {
    9.     if(RandomPos = 1){
    10.         print("1");
    11.     }
    12. }
     
  2. snortop

    snortop

    Joined:
    Dec 16, 2011
    Posts:
    194
    you set it as C# code?

    When it is Unity Javascript code
     
  3. RankXenon

    RankXenon

    Joined:
    Jan 20, 2013
    Posts:
    48
    This is unity script/javascript
    i am sure i isn't a c# file
     
  4. snortop

    snortop

    Joined:
    Dec 16, 2011
    Posts:
    194
    exactly, what I was trying to say.

    Thought you might have made it as a C# file.
     
  5. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    = is a variable assignment
    == is "equals to"

    since you can't assign a var within the brackets of an if block the compiler is trying it's best... so it's expecting "if(RandomPos)" ie ) instead of = and then well... the rest stems from that really.

    edit: holds for c# and unityscript
     
  6. RankXenon

    RankXenon

    Joined:
    Jan 20, 2013
    Posts:
    48
    oh yeah...how supid i am :/ , i haven't used unity for a while so i forgot :(