Grow
August 7, 2011, 3:11pm
1
Hello, I have some errors in this tutorial http://www.youtube.com/watch?v=KG26blhtYnA&feature=channel_video_title
Errors say this →
Assets/YoutubeTest/BaseCharacter.cs(91,142): error CS1729: The type ModifyingAttribute' does not contain a constructor that takes 2’ arguments
Assets/YoutubeTest/BaseCharacter.cs(91,49): error CS1502: The best overloaded method match for `ModifiedStat.AddModifier(ModifyingAttribute)’ has some invalid arguments
Assets/YoutubeTest/BaseCharacter.cs(91,49): error CS1503: Argument #1' cannot convert object’ expression to type `ModifyingAttribute’
Assets/YoutubeTest/BaseCharacter.cs(93,140): error CS1729: The type ModifyingAttribute' does not contain a constructor that takes 2’ arguments
Assets/YoutubeTest/BaseCharacter.cs(93,49): error CS1502: The best overloaded method match for `ModifiedStat.AddModifier(ModifyingAttribute)’ has some invalid arguments
Assets/YoutubeTest/BaseCharacter.cs(93,49): error CS1503: Argument #1' cannot convert object’ expression to type `ModifyingAttribute’
Assets/YoutubeTest/BaseCharacter.cs(95,135): error CS1729: The type ModifyingAttribute' does not contain a constructor that takes 2’ arguments
…
Here is my code:
using UnityEngine;
using System.Collections;
using System;
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];
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
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; }
}
public void AddExp(uint exp) {
_freeExp += exp;
CalculateLevel();
}
public void CalculateLevel(){
}
private void SetupPrimaryAttribute(){
for(int cnt = 0; cnt < _primaryAttribute.Length; cnt++){
_primaryAttribute[cnt] = new Attribute();
}
}
private void SetupVitals(){
for(int cnt = 0; cnt < _primaryAttribute.Length; cnt++){
_vital[cnt] = new Vital();
}
}
private void SetupSkills(){
for(int cnt = 0; cnt < _primaryAttribute.Length; cnt++){
_skill[cnt] = new Skill();
}
}
public Attribute GetPrimaryAttribute(int index) {
return _primaryAttribute[index];
}
public Vital GetVital(int index) {
return _vital[index];
}
public Skill GetSkill(int index) {
return _skill[index];
}
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.Constitution), 1));
//mana
GetVital((int)VitalName.Mana).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), 1));
}
private void SetupSkillModifiers() {
//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.Nimbleness), .33f));
//melee defence
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 offence
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 defence
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 offence
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 defence
GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nimbleness), .33f));
}
}
Please help
I haven’t been through your code because i did those tutorials and I know they worked so I would go back through it and see which bit you didn’t do right. Or pay the $10 and get his source code.
kral
August 7, 2011, 9:55pm
3
using UnityEngine;
using System.Collections;
using System; // enum clasına erişim
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 {
get{return _name;}
set{_name = value;}
}
public int Level {
get{return _level ;}
set{_level = value ;}
}
public uint FreeExp {
get{return _freeExp;}
set{_freeExp = value;}
}
public void AddExp(uint exp) {
_freeExp += exp;
CalculateLevel();
}
public void CalculateLevel() {
}
private void SetupPrimaryAttributes() {
for(int cnt = 0; cnt < _primaryAttribute.Length; cnt++){
_primaryAttribute[cnt] = new Attribute();
_primaryAttribute[cnt].Name = ((AttributeName)cnt).ToString();
}
}
private void SetupVitals() {
for(int cnt = 0; cnt < _vital.Length; cnt++)
_vital[cnt] = new Vital();
SetupVitalModifiers();
}
private void SetupSkills() {
for(int cnt = 0; cnt < _skill.Length; cnt++)
_skill[cnt] = new Skill();
SetupSkillModifiers();
}
public Attribute GetPrimaryAttribute(int index){
return _primaryAttribute[index];
}
public Vital GetVital(int index){
return _vital[index];
}
public Skill GetSkill(int index){
return _skill[index];
}
private void SetupVitalModifiers(){
//health
ModifyingAttribute healthModifier = new ModifyingAttribute();
healthModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
healthModifier.ratio = .5f;
GetVital((int)VitalName.Health).AddModifier(healthModifier);
//energy
ModifyingAttribute energyModifier = new ModifyingAttribute();
energyModifier.attribute = GetPrimaryAttribute((int)AttributeName.Constitution);
energyModifier.ratio = 1;
GetVital((int)VitalName.Energy).AddModifier(energyModifier);
//mana
ModifyingAttribute manaModifier = new ModifyingAttribute();
manaModifier.attribute = GetPrimaryAttribute((int)AttributeName.Willpower);
manaModifier.ratio = 1;
GetVital((int)VitalName.Mana).AddModifier(energyModifier);
}
private void SetupSkillModifiers(){
// 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.Nimbleness), .33f));
// melee defence
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));
// ranged offence
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 defence
GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Speed), .33f));
GetSkill((int)SkillName.Ranged_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Nimbleness), .33f));
// magic offence
GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), .33f));
GetSkill((int)SkillName.Magic_Offence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .33f));
// magic defence
GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Willpower), .33f));
GetSkill((int)SkillName.Magic_Defence).AddModifier(new ModifyingAttribute(GetPrimaryAttribute((int)AttributeName.Concentration), .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();
}
try this
I don’t think you’ve included the part of your script that’s causing the errors. The code you’ve posted looks correct, but as the error message says, there is no constructor for ModifyingAttribute with 2 parameters. Could you post your code from “ModifyingAttribute” please?
(I have done these tutorials myself, but I have made so many changes to the code along the way that I can’t do a compare to my own code I’m afraid.)
Grow
August 8, 2011, 2:31pm
6
I did it again and again all the tutorials, but always have this error. Oh i don’t have script ModifyingAttribute, have only Attribute, BaseStat, ModifiedStat, Skill, Vital, BaseCharacter
Grow
August 8, 2011, 3:00pm
7
Where i can find ModifyingAttribute code?
I had a similar problem and it was my ModifiedStat did not inherit from BaseStat, but instead I’d left monobehaviour from the default.
I’d make sure your ModifiedStat.cs starts like:
using System.Collections.Generic;
public class ModifiedStat : [B]BaseStat[/B] {
private List<ModifyingAttribute> _mods;
private float _modValue;
//yadayadayada
Grow
August 9, 2011, 1:12pm
9
My ModifiedStat script
using System.Collections.Generic;
public class ModifiedStat : BaseStat {
private List<ModifyingAttribute> _mods;
private int _modValue;
public ModifiedStat(){
_mods = new List<ModifyingAttribute>();
_modValue = 0;
}
public void AddModifier( ModifyingAttribute mod) {
_mods.Add(mod);
}
private void CalculateModValue() {
_modValue = 0;
if(_mods.Count > 0)
foreach(ModifyingAttribute att in _mods)
_modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
}
public new int AdjustBaseValue{
get{ return BaseValue + BuffValue + _modValue; }
}
public void Update(){
CalculateModValue();
}
}
public struct ModifyingAttribute {
public Attribute attribute;
public float ratio;
}
My Attribute script
public class Attribute : BaseStat {
public Attribute(){
ExpToLevel = 50;
LevelModifier = 1.05f;
}
}
public enum AttributeName {
Might,
Constitution,
Nimbleness,
Speed,
Concentration,
Willpower,
Charisma
}
My BaseStat script
public class BaseStat {
private int _baseValue;
private int _buffValue;
private int _expToLevel;
private float _levelModifier;
public BaseStat() {
_baseValue = 0;
_buffValue = 0;
_levelModifier = 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 LevelModifier {
get{ return _levelModifier; }
set{ _levelModifier = value; }
}
#endregion
private int CalculateExpToLevel(){
return (int)(_expToLevel * _levelModifier);
}
public void LevelUp(){
_expToLevel = CalculateExpToLevel();
_baseValue++;
}
public int AdjustedBaseValue{
get{ return _baseValue + _buffValue; }
}
}
Please help me. I trying again and again, but always it say this error.
I can’t figure this out have you please tell if you have
Grow:
My ModifiedStat script
using System.Collections.Generic;
public class ModifiedStat : BaseStat {
private List<ModifyingAttribute> _mods;
private int _modValue;
public ModifiedStat(){
_mods = new List<ModifyingAttribute>();
_modValue = 0;
}
public void AddModifier( ModifyingAttribute mod) {
_mods.Add(mod);
}
private void CalculateModValue() {
_modValue = 0;
if(_mods.Count > 0)
foreach(ModifyingAttribute att in _mods)
_modValue += (int)(att.attribute.AdjustedBaseValue * att.ratio);
}
public new int AdjustBaseValue{
get{ return BaseValue + BuffValue + _modValue; }
}
public void Update(){
CalculateModValue();
}
}
public struct ModifyingAttribute {
public Attribute attribute;
public float ratio;
}
My Attribute script
public class Attribute : BaseStat {
public Attribute(){
ExpToLevel = 50;
LevelModifier = 1.05f;
}
}
public enum AttributeName {
Might,
Constitution,
Nimbleness,
Speed,
Concentration,
Willpower,
Charisma
}
My BaseStat script
public class BaseStat {
private int _baseValue;
private int _buffValue;
private int _expToLevel;
private float _levelModifier;
public BaseStat() {
_baseValue = 0;
_buffValue = 0;
_levelModifier = 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 LevelModifier {
get{ return _levelModifier; }
set{ _levelModifier = value; }
}
#endregion
private int CalculateExpToLevel(){
return (int)(_expToLevel * _levelModifier);
}
public void LevelUp(){
_expToLevel = CalculateExpToLevel();
_baseValue++;
}
public int AdjustedBaseValue{
get{ return _baseValue + _buffValue; }
}
}
Please help me. I trying again and again, but always it say this error.
You can’t buy the codes right now the site isn’t working!
and I’m still stuck at this
Can someone help me with this?
I did the tutorial too and I remember one big “bug” that he fixed right at the beginning of the next tutorial, maybe it is this one…