1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. Unity 2017.1 beta is now available for download.
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  8. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    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;