• 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 Gilead7 · Feb 23, 2012 at 03:52 AM · value

Hack and Slash Tutorial Problem

Here we go again. This same line was used in another script, but it compiled just fine. Here is the entire code:

using UnityEngine; using System.Collections; using System; //access to enum class

public class BaseCharacter : MonoBehaviour {

 private string _name;
 private int _level;
 private uint _freeExp;
     
 private Attribute[] _primaryAttribute;
 private Vital[] _vital;        
 private Skill[] _skill;
 
 
 public void Awake(){
     _name=string.Empty;
     _level=0;
     _freeExp=0;
     
     _primaryAttribute= new Attribute[Enum.GetValues(typeof(AttributeName)).Length];
     _vital=new Vital[Enum.GetValues(typeof(VitalName)).Length];
     _skill=new Skill[Enum.GetValues(typeof(SkillName)).Length];    
     
     SetupPrimaryAttributes();
     SetupVitals();
     SetupSkills();
 }
     
 public string Name {
 set{ return _name; }
 get{ _name= value; }    
     
 }
 
 public int Level {
 set { return _level; }
 get { _level= value; }    
 }
 
 public uint FreeExp {
 set { return _freeExp; }
 get { _freeExp= value; }
 }
 
 public void AddExp(uint exp){
     _freeExp+= exp;
     CalculateLevel();
 }
 
 //take average of all player's skills and assign that as the player level
 public void CalculateLevel() {
     
     
 }
 
 private void SetupPrimaryAttributes() {
     for(int cnt=0; cnt < _primaryAttribute.Length; cnt++) {
     _primaryAttribute[cnt]=new Attribute();    
     }
 }
     
 private void SetupVitals() {
     for(int cnt=0; cnt < _vital.Length; cnt++) {
     _primaryVitals[cnt]=new Vital();    
     }
 }
         
 private void SetupSkills() {
     for(int cnt=0; cnt < _skill.Length; cnt++) {
     _primarySkills[cnt]=new Skill();    
     }
 }
 public Attribute GetPrimaryAttribute(int index) {
     return _primaryAttribute[index];
 }
 
 public Vital GetVitals(int index) {
     return _vital[index];
 }
 
 public Skill GetSkill(int index) {
     return _skill[index];
 }
 
 private void SetupVitalModifers() {
     // health
     GetVital=((int)VitalName.Life).AddModifer( new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution ), .5f));
         
     //energy
     GetVital=((int)VitalName.Energy).AddModifer(new ModifyingAttribute (GetPrimaryAttribute((int)AttributeName.Constitution ), 1));
     
     //mana
     GetVital=((int)VitalName.Mana).AddModifer( new ModifyingAttribute (GetPrimaryAttribute((int)AttributeName.Willpower ),  1)); 
 
 }
 
 private void SetupSkillModifers(){
     //melee offence
 GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Might), .33f));
 GetSkill((int)SkillName.Melee_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nibleness), .33f));
     //melee defense
 GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
 GetSkill((int)SkillName.Melee_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), .33f));
     //magic offense
 GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
 GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), .33f));
     //magic defense
 GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
 GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), .33f));
     
     //ranged offense
 GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));    
 GetSkill((int)SkillName.Ranged_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
     //ranged defense
 GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
 GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nibleness), .33f));
 }
 
 public void StatUpdate() {
 for (int cnt=0; cnt < _vital.Length; cnt++ )
         _vital[cnt].Update();
 for (int cnt=0; cnt< _skill.Length; cnt++)
         _skill[cnt].Update();
 }

} The name value doe not exist, yet in BaseStat, it worked just fine as a setter and getter. public int ExpToLevel { get{ return _expToLevel;} set{ _expToLevel=value;} } Other Errors: Assets/Scripts/Character Classes/BaseCharacter.cs(31,14): error CS0127: BaseCharacter.Name.set': A return keyword must not be followed by any expression when method returns void Assets/Scripts/Character Classes/BaseCharacter.cs(31,14): error CS0029: Cannot implicitly convert type string' to void' Assets/Scripts/Character Classes/BaseCharacter.cs(37,15): error CS0127: BaseCharacter.Level.set': A return keyword must not be followed by any expression when method returns void Assets/Scripts/Character Classes/BaseCharacter.cs(37,15): error CS0029: Cannot implicitly convert type int' to void' Assets/Scripts/Character Classes/BaseCharacter.cs(42,15): error CS0127: `BaseCharacter.FreeExp.set': A return keyword must not be followed by any expression when method returns void Please help! Thanks!

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 ZweiD · Feb 23, 2012 at 07:54 AM 0
Share

may I ask where you found that tutorial?

avatar image Gilead7 · Feb 23, 2012 at 06:04 PM 0
Share

http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial

2 Replies

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

Answer by ZweiD · Feb 23, 2012 at 07:45 AM

you swapped the getters and setters in your code.

 public int MyValue {
   get { return _myValue; }
   set { _myValue = value; }
 }
Comment
Add comment · Show 2 · 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 Gilead7 · Feb 23, 2012 at 06:22 PM 0
Share

one issue down, now it;s saying _primaryVital doesn't exist in this context. I need to therefore define it somewhere. Right?

avatar image Gilead7 · Feb 23, 2012 at 06:30 PM 0
Share

Okay, I changed some variable names around and got past that portion. This next part I have no idea.

avatar image
0

Answer by Gilead7 · Feb 23, 2012 at 11:17 PM

private void SetupVitalModifers() { // health GetVital=((int)VitalName.Life).AddModifer( new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution ), .5f));

     //energy
     GetVital=((int)VitalName.Energy).AddModifer(new ModifyingAttribute (GetPrimaryAttribute((int)AttributeName.Constitution ), 1));
     
     //mana
     GetVital=((int)VitalName.Mana).AddModifer( new ModifyingAttribute (GetPrimaryAttribute((int)AttributeName.Willpower ),  1)); 
 
 }

Assets/Scripts/Character Classes/BaseCharacter.cs(89,48): error CS1061: Type int' does not contain a definition for AddModifer' and no extension method AddModifer' of type int' could be found (are you missing a using directive or an assembly reference?) Are they not supposed to be cast as ints?

Comment
Add comment · Show 1 · 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 ZweiD · Feb 24, 2012 at 08:49 AM 0
Share

where in your code did you define AttributeName?

reasoning from their name, they probably are strings. you can't just cast strings to ints, you need to provide something different.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

what is wrong with my GUI script? 1 Answer

Timer and TextMesh issue.... 1 Answer

Reducing a value over time 2 Answers

Edit GameObject.Variable 1 Answer

Changing enum values with int label 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