0

Basically I created this skill class:

public class skill
{
    public int          level { get; set; }             //Level of the skill    (average of sub-skills' levels)
    public int          arrayCount { get; set; }        //Number of skill/levels in the below arrays
    public string[]     sub_skills { get; set; }        //Names of sub-skills   ([0] connect's to levels' [0], etc.)
    public int[]        sub_levels { get; set; }        //Levels of sub-skills  ([0] connect's to names' [0], etc.)
    void set(int l, int a, string[] sub_s, int[] sub_l)
    {
        this.level          = l;                //Sets the skill's level to the input'd l value
        this.arrayCount     = a;                //Sets the skill's array count to the input'd a value
        for (int i = 0; i < arrayCount; i++)    //For loop to assign each value in both arrays
        {
            this.sub_skills[i] = sub_s[i];      //Assigns each input'd sub_s array value to each sub_skills value
            this.sub_levels[i] = sub_l[i];      //Assigns each input'd sub_l array value to each sub_levels value
        }

    }
}

Now I have created another class, player:

public class Player
{
    public string   name { get; set; }          //Name of Player
    public int      level { get; set; }         //Player's combat level             (average of combat-related skills' levels)
    //Start Thievery skill block
    string[] thief_s = { "lockpicking", "looting", "pickpocketing", "sneaking" };       //Array for thievery's sub-skill names
    int[] thief_i = { 1, 1, 1, 1 };                                                     //Array for thievery's sub-levels
    skill thievery      = new skill();          //Creates the skill of Thievery     (stealing items / passing unnoticed)
    //Start Melee skill block
    skill melee         = new skill();          //Creates the skill of Melee        (close-range, strong combat)
    //Start Archery skill block
    skill archery       = new skill();          //Creates the skill of Archery      (long-range, weak combat)
    //Start Magicka skill block
    skill magicka       = new skill();          //Creates the skill of Magicka      (medium-range, medium combat)
    //Start Craftship skill block
    skill craftship     = new skill();          //Creates the skill of Craftship    (retreivement then creation of items from materials)


}

How can I use the set() method from the skill class inside the player class, for a specific skill created inside the player class? For example you can see how I have the skill thievery created there, already with its arrays for it's sub-level's names and levels (variables in the skill class). How can I access thievery's set() function and also use the arrays in it to set thievery's variables? I've tried the line thievery.set(// insertvarshere) but my IDE keeps throwing errors. (I'm using Microsoft Visual Studio Ultimate 2010)

EDIT: Thanks everyone. For some reason setting the set() function to public didn't change anything. When I call thievery.set() my IDE throws red lines under thievery. I'm going to take Charles advice and make the sub-skills skills, and then, if it's possible, apply some sort of tag to them to mark them as part of the major skill. Is that possible, or must I create my own class/function etc. for a tag?

5
  • what are the IDE errors? Commented Jul 22, 2013 at 17:29
  • 1
    Change void set(int l, int a, string[] sub_s, int[] sub_l) to public void set(int l, int a, string[] sub_s, int[] sub_l). Is that the problem ? Commented Jul 22, 2013 at 17:29
  • Change the access modifier of set to public. Commented Jul 22, 2013 at 17:30
  • You should really consider using a separate class for Subskill instead of using parallel arrays and a constructor for your Skill that also includes the name of the skill, that would make a lot more sense Commented Jul 22, 2013 at 17:38
  • Thanks everyone. I'm going to take Charles advice and make the sub-skills skills, and then, if it's possible, apply some sort of tag to them to mark them as part of the major skill. Is that possible? Commented Jul 22, 2013 at 18:30

3 Answers 3

3

On the face of it, you need to make it public:

public void set(int l, int a, string[] sub_s, int[] sub_l) {
  ...

Then, for each skill instance, you can call it:

thievery.set( ... );

Where you want to call it, and with what parameter arguments, is up to you.

Sign up to request clarification or add additional context in comments.

1 Comment

I've tried calling it within the player class but it underlines thievery in thievery.set( ... ); and says that it is being used as a type but it is a field.
0

Unless I'm missing something here you'd need to make the set method visible by either making it public or building a new public method that called it. It's possible that you need an abstracted method that calls set the way you want it called so that it's used properly by consumers.

Comments

0

Where are you trying to call the set method in the Player class. You can only call the set method in another method or constructor of Player class. May be that is why you are getting errors.

Edit: You also need to add public for the method of course.

3 Comments

Ah, thank you. I was calling it outside of a function inside player. I will try adding it within a function.
You are welcome. You can only declare variables, properties, instructions and define constructors, destructors within a class. You can't do method calls.
Thank you. I've re-written the entire player class and everything works. (but it has about 60 more lines, heh)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.