Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

what is wrong with this?

Discussion in 'Scripting' started by Feyhu, Aug 11, 2011.

  1. Feyhu

    Feyhu

    Joined:
    Sep 14, 2010
    Posts:
    211
    float travel = (travelSpeed *= 10 *= Time.deltaTime);
    ^^^
    located under the update function in a c# script. it keeps saying "Assets/Scripts/UnitControlAlly.cs(18,49): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer"
     
  2. eTag96

    eTag96

    Joined:
    Oct 24, 2010
    Posts:
    110
    you must do
    Code (csharp):
    1. float travel = (travelSpeed * 10 * Time.deltaTime);
    2.  
    simple.
     
  3. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    You can't perform two assignments in the same line is my guess. I've never tried it. An assignment is when you use a single "=" sign to assign a value to a variable. For completeness... A "==" (double equals) sign is a comparison.

    I think you want
    PHP:
    float travel travelspeed 10 Time.deltaTime
     
  4. eTag96

    eTag96

    Joined:
    Oct 24, 2010
    Posts:
    110
    which is what I said? :D (basically)
     
  5. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    Cheater. I had to type useful information which delayed my post by 0.2341 seconds, which you needed to win...
     
  6. eTag96

    eTag96

    Joined:
    Oct 24, 2010
    Posts:
    110
    haha, it's not a contest! whatever helps him... the quick fix :p or the info. :D thanks for really helping him though!
     
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,726
    Should have pooled your useful information, which would have kept the speed up. I recommend you try http://poolmanager.path-o-logical.com/ - works well... oh wait! :D
     
  8. justinlloyd

    justinlloyd

    Joined:
    Aug 5, 2010
    Posts:
    1,681
    Depending on your language, and most C-derivatives support the syntax, you can perform two assignments on a single line. The error is not in the assignments but in the fact that two calculations are attempting to be performed, which is a clear syntax error.
     
  9. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    @Hippo: Lol. Totally. I'm firing up the Profiler next time to see where I lost those ms
    @Justin: True, but even if it is legal, I would argue it is bad form. Makes things hard to read.
     
  10. Feyhu

    Feyhu

    Joined:
    Sep 14, 2010
    Posts:
    211
    thanks guys
     
  11. justinlloyd

    justinlloyd

    Joined:
    Aug 5, 2010
    Posts:
    1,681
    @Rafes: I avoid at all costs style discussions because it is a holy war over whose is better/best. :) All syntax usage has its place, it depends on how you use it and how you abuse it that matters. Good software development is not just about knowing how to write code that solves a problem. :)
     
unityunity