Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sorting Error and Other Error

Discussion in 'Scripting' started by Darth_Escar, May 24, 2015.

  1. Darth_Escar

    Darth_Escar

    Joined:
    Apr 13, 2015
    Posts:
    30
    I have this code here.
    Code (JavaScript):
    1. #pragma strict
    2. import System.Collections.Generic;
    3.  
    4. var Speeds = new List.<int>();
    5. var Stat = "RIOne";
    6. var Moving = 0;
    7. var Turn = 0;
    8.  
    9. //(I have a status (Stat) reference here, but I'm not showing it here, because It'd take too long for
    10. //anybody other than me to understand for it to be worthwhile to attempt doing so.
    11.  
    12. function Update ()
    13. {
    14.     Debug.Log(Stat);
    15.    
    16.     if (Stat == "RITwo")
    17.     {
    18.         Speeds.Sort; //This line gets the error
    19.         var C = 0;
    20.         C++;
    21.         Turn = Speeds[C];
    22.        
    23.         Debug.Log("Recieved Input");
    24.     }
    25. }
    I get the error "Expressions in statements must only be executed for their side effects". I have the line its for marked in the code. With the way this script works, that line would sort all of the speed variables it gets from another script I have. To my understanding, that error occurs when a function does not do anything. I could post that other script if necessary, but its really big all it does for this one is change the status, and put variables into the collection.

    I also have found a weird bug in Unity. Anytime I get script error (does not happen for other errors or Debug Logs) It shows up blank unless I restart Unity. This one is really annoying, so help on this, as well as the other one, is highly appreciated.
     
  2. roger0

    roger0

    Joined:
    Feb 3, 2012
    Posts:
    1,208
    maybe you need to put parenthesis at the end. Speeds.Sort();
     
  3. Darth_Escar

    Darth_Escar

    Joined:
    Apr 13, 2015
    Posts:
    30
    Thankyou, it worked! I feel pretty dumb now, considering that I missed such a simple thing.