C# help

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

  1. axeves

    axeves

    New Member

    Joined:
    Jan 8, 2011
    Messages:
    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

    New Member

    Joined:
    Jan 8, 2011
    Messages:
    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

    New Member

    Joined:
    Apr 5, 2008
    Messages:
    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

    New Member

    Joined:
    Jan 8, 2011
    Messages:
    7
    Oh S***, fucking auto-complete :( :( :( :( :( rawr

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

    axeves

    New Member

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

    irishstorm

    New Member

    Joined:
    Jun 25, 2012
    Messages:
    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

    New Member

    Joined:
    May 1, 2013
    Messages:
    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;