Page 1 of 1

C# code problem.*SOLVED*

Posted: Fri Mar 02, 2012 10:24 pm
by Shihonoryu
Aight, getting three errors:


Assets/scripts/Character classes/BaseCharacter.cs(21,73): error CS0246: The type or namespace name `AttributeName' could not be found. Are you missing a using directive or an assembly reference?


Assets/scripts/Character classes/BaseCharacter.cs(21,56): error CS1502: The best overloaded method match for `System.Enum.GetValues(System.Type)' has some invalid arguments


Assets/scripts/Character classes/BaseCharacter.cs(21,56): error CS1503: Argument `#1' cannot convert `object' expression to type `System.Type'


I think by solving the first, the rest will fall into order. Here is my code:

BaseCharacter:

Code: Select all

using UnityEngine;
using System.Collections;
using System;                            //added to acces the 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];
		
		
	}
	
	
	// 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;
	
		
		
	}
	
	
	
	private  void SetupPrimaryAttributes(){
		
		
		
	}
	
	private void SetupVitals(){
		
		
	}
	
	
	private void SetupSkills(){
		
		
	}
	                                       
	                                       
	                                    
}

and Attribute

Code: Select all

public class Attribute : BaseStat {
	
	
	public Attribute() {
	 exptolevel = 50;
	 LevelModifier = 2.05f;
}
	
	public enum AttributeName {
	might,      
	Constitution,
	Nimbleness,
	Speed,
	Concentration,
	Willpower,
	Charisma
		
	}
	
	
}



Re: C# code problem.

Posted: Wed Mar 07, 2012 9:05 am
by VZdemon
lol your doing burgzerg's tutorials, nice. i'll just give my codes here

(i trimed it down alot because i'm already in tutorial 102)

Code: Select all

using UnityEngine;
using System.Collections;
using System;//added to acces the 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];
		
		SetupPrimaryAttribute();
		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();	
	}
	
	
	//take avg of all the player skills and assign that as the playe level
	public void CalculateLevel() {
			
	}
	
	private void SetupPrimaryAttribute() {
		
	}
	
	private void SetupVitals() {
	
	}
	
	private void SetupSkills() {

	}
}
for the attribute code you just need to organize your code, and take the enumaration out of the class brackets.
here did it for you

Attribute.cs

Code: Select all

public class Attribute : BaseStat {

   public Attribute() {
      exptolevel = 50;
      LevelModifier = 2.05f;
   }     
}

public enum AttributeName {
   might,      
   Constitution,
   Nimbleness,
   Speed,
   Concentration,
   Willpower,
   Charisma
}
   

Re: C# code problem.

Posted: Wed Mar 07, 2012 9:34 am
by Chris
What IDE are you using to write this? Hit ctrl+. to get a list of possible references with Visual Studio. Your problem is most likely that you are simply forgetting to implement something.

Re: C# code problem.

Posted: Tue Mar 13, 2012 4:30 am
by Shihonoryu
Lol figured it out... enum was in the wrong placed, never bothered to look at scope -.- stupid me, i should know better, this isnt my first time programming XD

Re: C# code problem.

Posted: Wed Mar 14, 2012 7:41 pm
by VZdemon
-_- it's exactly what i said in my post
VZdemon wrote:for the attribute code you just need to organize your code, and take the enumaration out of the class brackets.

Re: C# code problem.

Posted: Thu Mar 15, 2012 3:50 am
by Shihonoryu
Haha i know, but nobody responded to this thread for a while, so i fixed it before i saw your post, and didnt see your post when i posted my post :P