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

C# help

Discussion in 'Scripting' started by axeves, Jan 8, 2011.

  1. axeves

    axeves

    Joined:
    Jan 8, 2011
    Posts:
    7
    This is my code;

    Code (csharp):
    1. using System.Collections.Generic;
    2.  
    3.  
    4.  
    5. public class ModifiedStat : BaseStat {
    6.  
    7.     private List<ModifyingAttribute> _mods;
    8.  
    9.     private int _modValue;
    10.  
    11.    
    12.  
    13.     public ModifiedStat() {
    14.  
    15.         _mods = new List<ModifyingAttribute>();
    16.  
    17.         _modValue = 0;
    18.  
    19.     }
    20.  
    21.    
    22.  
    23.     public void AddModifier( ModifyingAttribute mod) {
    24.  
    25.         _mods.Add(mod);
    26.  
    27.     }
    28.  
    29.    
    30.  
    31.     private void CalculateModValue() {
    32.  
    33.         _modValue = 0;
    34.  
    35.        
    36.  
    37.         if(_mods.Count > 0)
    38.  
    39.             foreach(ModifyingAttribute att in _mods)
    40.  
    41.                 _modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
    42.  
    43.     }
    44.  
    45.    
    46.  
    47.     public new int AdjustedBaseValue {
    48.  
    49.                 get{ return BaseValue + BuffValue + _modValue; }
    50.  
    51.     }
    52.  
    53.    
    54.  
    55.     public void Update() {
    56.  
    57.         CalculateModValue();
    58.  
    59.     }
    60.  
    61. }
    62.  
    63.  
    64.  
    65. public struct ModifyingAttribute {
    66.  
    67.     public Attribute attribute;
    68.  
    69.     public float ratio;
    70.  
    71.    
    72.  
    73.     public ModifyingAttribute(Attribute att, float rat) { //error line
    74.  
    75.         Attribute = att;
    76.  
    77.         ratio = rat;
    78.  
    79.     }
    80.  
    81. }
    This is the error i am getting:


    Assets/Scripts/Character Classes/ModifiedStat.cs(38,17): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer



    Assets/Scripts/Character Classes/ModifiedStat.cs(37,61): error CS0171: Field `ModifyingAttribute.attribute' must be fully assigned before control leaves the constructor

    This is from thehttp://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial tutorials.

    I have absolutely no idea why this happens, as i have the exact same code as in the tutorial, and that runs fine. :(

    Any help appreciated.
     
  2. axeves

    axeves

    Joined:
    Jan 8, 2011
    Posts:
    7
    Attribute = att; is error Assets/Scripts/Character Classes/ModifiedStat.cs(38,17): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer


    ratio = rat; is error
    Assets/Scripts/Character Classes/ModifiedStat.cs(37,61): error CS0171: Field `ModifyingAttribute.attribute' must be fully assigned before control leaves the constructor
     
  3. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Look at these two lines:

    Code (csharp):
    1. public Attribute attribute;
    2. public float ratio;
    And then at these two lines:

    Code (csharp):
    1. Attribute = att;
    2. ratio = rat;
    In the above excerpt, the second line is correct, but the first line isn't. Do you see the difference between the two?
     
  4. axeves

    axeves

    Joined:
    Jan 8, 2011
    Posts:
    7
    Oh S***, F***ing auto-complete :( :( :( :( :( rawr

    Thanks Jesse, i guess my brain died. :)
     
  5. axeves

    axeves

    Joined:
    Jan 8, 2011
    Posts:
    7
    If anyone wonders, attribute isn't capitalized.
     
  6. irishstorm

    irishstorm

    Joined:
    Jun 25, 2012
    Posts:
    8
    You sir, have helped me alot!!!! Thank you very much!!!!!!:cool:
    I did the same with a capital A instead of a small a.
     
  7. Christian-wood

    Christian-wood

    Joined:
    May 1, 2013
    Posts:
    2
    So I keep getting this error for two different lines "Assets/Standard Assets/Scripts/General Scripts/ActivateTrigger.cs(43,58): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer"

    targetGameObject.active () = true;




    targetGameObject.active () = false;