Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by junkdog8 · May 15, 2014 at 10:28 PM · tutorialsettersgetters

problems with setters and getters.

hey, so i am trying to follow this tutorial to get a better understanding of the workings of an RPG

tutorial https://www.youtube.com/watch?v=li6ha2d8Arw&list=PLE5C2870574BF4B06

the only problem is that i followed the tutorial exactly(except for a few errors on his part) and i am getting some really weird errors, not sure if it is because of the difference in versions or what but i could use a little help.

here is the code that i wrote.

 public class BaseStat
 {
     private int _baseValue;            //the base value of the stat.
     private int _buffValue;            //the amount of the buff to this stat.
     private int _expToLevel;        //total amount of exp to reach next level.
     private float _levelModifier;    //the modifier applied to the exp to raise the skill.
 
     public int baseStat()
     {
         _baseValue = 0;
         _buffValue = 0;
         _levelModifier = 1.1f;
         _expToLevel = 100;
     }
 
     //base setters and getters.
     public int BaseValue()
     {
         get{ return _baseValue; }
         set{ _baseValue = value }
     }
 
     public int BuffValue()
     {
         get{return _buffValue;}
         set{_buffValue = value;}
     }
 
     public int ExpToLevel()
     {
         get{return _expToLevel;}
         set{_expToLevel = value;}
     }
 
     public float LevelModifier ()
     {
         get{return _levelModifier;}
         set{_levelModifier = value;}
     }
 
     private int CalulateExpToLevel()
     {
         return (int)(_expToLevel * _levelModifier);
     }
 
     private void LevelUp()
     {
         _expToLevel = CalulateExpToLevel;
         _baseValue++;
     }
 
     public int AdjustedValue()
     {
         return _baseValue + _buffValue;
     }
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · May 15, 2014 at 10:44 PM 1
Share

You seem to be writing properties like they're functions.

avatar image Kiwasi · May 16, 2014 at 12:22 AM 2
Share

Don't bother with custom properties unless you actually need them. Auto implemented properties work just as well. For your implementation as written you might as well just use public variables with no properties.

Properties only make sense when you need to control the output or input. Like

 // Other objects can see this but cannot assign a value
 public int life {get; private set;} 
 
 // This set up ensures input values are above zero
 public int life {
     get {
         return life;
     }
     set {
         if (value > 0 ) {
             life = value;
         } else {
             life = 0;
         }
     }
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by MakeCodeNow · May 15, 2014 at 11:12 PM

Properties don't have () after the name. It's just

 public int BaseValue
 {
   //...
 } 
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image junkdog8 · May 17, 2014 at 11:04 PM 0
Share

this fixed it and i have been able to fix all but one error. i am getting error CS0161: 'BaseStat.baseStat()': not all code paths return a value. not quite sure what that means any ideas?

avatar image MakeCodeNow · May 18, 2014 at 05:21 AM 0
Share

First off, c# error codes are incredibly Google-able. Try it sometime.

This error means you created a function that returns something (an int) but you don't return anything in your function.

avatar image junkdog8 · May 19, 2014 at 06:31 AM 0
Share

i did actually google it but didn't understand the answer it gave, but i ended up figuring it out anyways.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

BurgZergArcade Unity tutorial 19-20 errors. 0 Answers

Error CS1502 help! 1 Answer

I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer

C# generics and getters/setters with Unity iPhone 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges