C# code problem.*SOLVED*

got scripts? Need scripts?
Post Reply
Shihonoryu
Posts: 255
Joined: Sun Dec 12, 2010 7:30 am

C# code problem.*SOLVED*

Post 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
		
	}
	
	
}


Last edited by Shihonoryu on Mon Apr 16, 2012 7:08 pm, edited 1 time in total.
User avatar
VZdemon
Posts: 93
Joined: Thu Nov 25, 2010 1:55 pm

Re: C# code problem.

Post 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
}
   
it's VZdaemon on xbox live
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: C# code problem.

Post 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.
Fighting for peace is declaring war on war. If you want peace be peaceful.
Shihonoryu
Posts: 255
Joined: Sun Dec 12, 2010 7:30 am

Re: C# code problem.

Post 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
User avatar
VZdemon
Posts: 93
Joined: Thu Nov 25, 2010 1:55 pm

Re: C# code problem.

Post 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.
it's VZdaemon on xbox live
Shihonoryu
Posts: 255
Joined: Sun Dec 12, 2010 7:30 am

Re: C# code problem.

Post 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
Post Reply

Return to “Scripting/Coding”