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 Goofball · Aug 31, 2012 at 07:03 PM · tutorialrpg

Terrible problem with scripts to create character for RPG

It either has 22 errors or 108, once it was down to about 3 then back to 108. It all started after I had made my BaseCharacter class yesterday, I'm beggin for help, it's flustering the hell out of me.

 public class BaseStat {
     private int _baseValue;
     private int _buffValue;
     private int _expToLevel;
     private float _levelMod;
 
     public BaseStat(){
         _baseValue = 0;
         _buffValue = 0;
         _levelMod = 1.1f;
         _expToLevel = 100;
     }
     
     #region Basic 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 LevelMod {
         get{ return _levelMod; }
         set{ _levelMod = value; }
     }
     #endregion
     
     private int CalculateExpToLevel(){
         return (int)(_expToLevel * _levelMod);
     }
     
     public void LevelUp(){
         _expToLevel = CalculateExpToLevel();
         _baseValue++;
     }
     
     public int AdjustedBaseValue{
         get{ return _baseValue + _buffValue; }    
     }    
 }
 
 
 
 using System.Collections.Generic;
 
 public class ModifiedStat : BaseStat {
     private List<ModifyingAttribute> _mods;            //List to hold modifiers
     private int _modValue;                            //Value of modifier
     
     public ModifiedStat(){
         _mods = new List<ModifyingAttribute>();        //Initialize list of modifiers
         _modValue = 0;                                //Set modifier value to 0
     }
     
     //Function to add modifiers to the list
     public void AddModifier(ModifyingAttribute mod){
         _mods.Add(mod);
     }
     
     
     private void CalculateModValue(){
         _modValue = 0;                                            
         
         //If there are any mods in the list, then 
         //for each mod it will add (adjusted value * set ratio of the attribute
         if(_mods.Count > 0)
             foreach(ModifyingAttribute att in _mods)
                 _modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
     }
     
     //Adds the normal value of your attributes with the value of buffs and modifiers
     public new int AdjustedBaseValue {
         get{ return BaseValue + BuffValue + _modValue; }
     }
     public void Update() {
         CalculateModValue();
     }
 }
 
 public struct ModifyingAttribute{
     public Attribute attribute;
     public float ratio;
     
     public ModifyingAttribute(Attribute att, float rat){
         attribute = att;
         ratio = rat;
     }
 }
 
 
 
 using System;
 
 public class Attribute : BaseStat{
     
     public Attribute(){
         ExpToLevel = 50;
         LevelMod = 1.05f;
     }
     
     public enum AttributeName {
         Constitution,
         Strength,
         Dexterity,
         Intellect,
         Vitality,
         Haste
     }
 }
 
 
 public class Vital : ModifiedStat {
     private int _currValue;
         
     public Vital(){
         _currValue = 0;
         ExpToLevel = 50;
         LevelMod = 1.1f;
     }
     public int CurrValue {
         get{ 
             if (_currValue > AdjustedBaseValue)
                 _currValue = AdjustedBaseValue;
             return _currValue; 
         }
         set{_currValue = value; }
     }
 }
 
 public enum VitalName {
     Health,
     Energy,
     Mana
 }
 
 
 
 public class Skill : ModifiedStat {
     private bool _known;
     
     public Skill() {
         _known = false;
         ExpToLevel = 25;
         LevelMod = 1.1f;
     }
     
     public bool Known {
         get{ return _known; }
         set{ _known = value; }
     }
 }
 
 public enum SkillName {
     Melee_Offense,
     Melee_Defense,
     Ranged_Offense,
     Ranged_Defense,
     Caster_Offense,
     Caster_Defense,
 }
 
 
 
 using System.Collections;
 using System;
 
 public class BaseCharacter : MonoBehaviour {
     #region Private Variables
     private string _name;                                        //Holds name of character
     private int _level;                                            //Holds level
     private uint _freeExp;                                        //Holds extra exp (uint stores only positive numbers)
 
     private Attribute[] _primaryAttribute;                        //Array of attributes for the character
     private Vital[] _vital;                                        //Array of vital assets to the character
     private Skill[] _skill;                                        //Array of skills for the character
     #endregion
     
     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();
     }
     #region Basic Setters and Getters
     public string Name {
         get{ return _name; }
         set{ _name = value; }
     }
     public int Level {
         get{ return _level; }
         set{ _level = value; }
     }
     public uint FreeExp {
         get{ return _freeExp; }
         set{ _freeExp = value; }
     }
     #endregion
     
     public void AddExp (uint exp) {
         _freeExp += exp;
     }
     public void CalculateLevel () {
         
     }
     #region Average of Attributes, Vitals, and Skills
     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++) {
             _vital[cnt] = new Vital();
         }
     }
     private void SetupSkills () {
         for(int cnt = 0; cnt < _skill.Length; cnt++) {
             _skill[cnt] = new Skill();
         }
     }
     #endregion
     
     #region Returns Attributes, Vitals, and Skills to int Index
     public Attribute GetPrimaryAttribute(int index) {
         return _primaryAttribute[index];
     }
     
     public Vital GetVital(int index) {
         return _vital[index];
     }
     
     public Skill GetSkill(int index) {
         return _skill[index];
     }
     #endregion
     
     #region Vital Modifiers
     private void SetupVitalModifiers(){
         //health
         GetVital((int)VitalName.Health).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), .5f));
         
         //energy
         GetVital((int)VitalName.Energy).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Dexterity), 1));
         
         //mana
         GetVital((int)VitalName.Mana).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Intellect), 1));
     }
     /*private void SetupVitalModifiers(){
         //health
         ModifyingAttribute healthModifier = new ModifyingAttribute();
         healthModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
         healthMod.ratio = 1;
         
         GetVital((int)VitalName.Health).AddModifier(energyModifier);
         
         //energy
         ModifyingAttribute energyModifier = new ModifyingAttribute();
         energyModifier.attribute = GetPrimaryAttribute((int)AttributeName.Dexterity);
         energyMod.ratio = 1;
         
         GetVital((int)VitalName.Energy).AddModifier(energyModifier);
         
         //mana
         ModifyingAttribute manaModifier = new ModifyingAttribute();
         manaModifier.attribute = GetPrimaryAttribute((int)AttributeName.Intellect);
         manaMod.ratio = 1;
         
         GetVital((int)VitalName.mana).AddModifier(manaModifier);
     }*/
     #endregion
     
     #region Skill Modifiers
     private void SetupSkillModifiers(){
 
         //Melee offense        
         GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Might), .33f));
         GetSkill((int)SkillName.Melee_Offense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Dexterity), .33f));
         
         //Melee defense        
         GetSkill((int)SkillName.Melee_Defense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Dexterity), .33f));
         GetSkill((int)SkillName.Melee_Defense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), .33f));
         
         //Ranged offense    
         GetSkill((int)SkillName.Ranged_Offense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Dexterity), .33f));
         GetSkill((int)SkillName.Ranged_Offense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Haste), .33f));
         //Ranged defense
         GetSkill((int)SkillName.Ranged_Defense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Dexterity), .33f));
         GetSkill((int)SkillName.Ranged_Defense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Constitution), .33f));
         
         //Caster offense    
         GetSkill((int)SkillName.Caster_Offense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Intellect), .33f));
         GetSkill((int)SkillName.Caster_Offense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Haste), .33f));
         //Caster defense    
         GetSkill((int)SkillName.Caster_Defense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Intellect), .33f));
         GetSkill((int)SkillName.Caster_Defense).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Vitality), .33f));
     }
     /*private void SetupSkillModifiers(){
         ModifyingAttribute MeleeOffenseModifier1 = new ModifyingAttribute();
         ModifyingAttribute MeleeOffenseModifier2 = new ModifyingAttribute();
         
         MeleeOffenseModifier1.attribute = GetPrimaryAttribute((int)AttributeName.strength);
         MeleeOffenseModifier1.ratio = .33f;
         
         MeleeOffenseModifier2.attribute = GetPrimaryAttribute((int)AttributeName.strength);
         MeleeOffenseModifier2.ratio = .33f;
         
         GetSkill((int)SkillName.Melee_Offense).AddModifier(MeleeOffenseModifier1);
         GetSkill((int)SkillName.Melee_Offense).AddModifier(MeleeOffenseModifier2);
     }
     */
 
     
     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();
             
     }
     #endregion
 }
Comment
Add comment · Show 1
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 landon912 · Aug 31, 2012 at 07:57 PM 0
Share

Can you post some examples of the errors? (not all 108 if that's how many there is)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by create3dgames · Aug 31, 2012 at 07:24 PM

Goodness. One thing's for sure, that's too much code. Use JavaScript.

Comment
Add comment · Show 4 · 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 MathieuBarbier · Aug 31, 2012 at 10:41 PM 0
Share

why does he need to use JavaScript ??

avatar image create3dgames · Aug 31, 2012 at 10:55 PM 0
Share

Because that's what everyone else uses and he will get much more help with his scripts. duh...

avatar image MathieuBarbier · Sep 01, 2012 at 12:06 AM 0
Share

well I don't really think so. Do you have any source to prove that point ? Beside that if you can read UnityScript you can read C#.

avatar image landon912 · Sep 01, 2012 at 12:17 AM 0
Share

I don't want to say this but more "pros" use C#, that can be proven. Also like ^ said if you can read JavaScript then you can at least understand 80% of C#

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

11 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

Related Questions

Hack and Slash tutorial Vitals and Skill points not showing up 1 Answer

good tutorials for 2d action rpg?,Good tutorials on 2D action-rpg? 1 Answer

problems with setters and getters. 1 Answer

Error CS1503, Error CS1502 1 Answer

Unable to reference a component. 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