Unity Community


Results 1 to 7 of 7

Thread: C# help


  1. Posts
    7

    C# help

    This is my code;

    Code:  
    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-s...ngine-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. 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. Posts
    2,857
    Look at these two lines:

    Code:  
    1. public Attribute attribute;
    2. public float ratio;

    And then at these two lines:

    Code:  
    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. Posts
    7
    Oh shit, fucking auto-complete rawr

    Thanks Jesse, i guess my brain died.


  5. Posts
    7
    If anyone wonders, attribute isn't capitalized.


  6. Posts
    8
    Quote Originally Posted by axeves View Post
    If anyone wonders, attribute isn't capitalized.
    You sir, have helped me alot!!!! Thank you very much!!!!!!
    I did the same with a capital A instead of a small a.


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

    targetGameObject.active () = true;

    &


    targetGameObject.active () = false;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •