项目的意外符号

时间:2015-12-15 19:38:41

标签: c# for-loop

我无法理解为什么我的代码存在“意外符号”。我正在为项目使用for循环,这几行代码给我带来了问题。我猜它与某些地方没有括号/半绞线有关,但我不知道它会在哪里。我可以帮助确定需要纠正此错误的位置吗?  enter image description here

enter image description here

以下是存在错误的完整代码

 // Use this for initialization
void Start()
{
    string[] imagesNames = new string[3] { "portrait01", "portrait02", "portrait03" };
    //images [0] = CreateSprite ("portrait01");
    //images[1] = CreateSprite ("portrait02");
    //images[2] = CreateSprite ("portrait03");
    string[] professionNames = new string[3] {"Karate fighter", "Ninja Figher", "Samurai Fighter"};
    string[] professionDescriptions = new string[3] { "Use hand to hand combat for powerful attacks! Req: Strength = 13 and Special = 10", 
        "Use high stealth and sneak attacks to suprize you enemies! Req: Speed = 15 or Strength = 9", 
        "Use your wisdom to reverse attacks with 2x the power! Req: Wisdom = 14 or Special = 13" };

    string[] professionImageNames = new string[3] { "profession01", "profession02", "profession03"};
    int[] [] minRequirements = { new int [3] {11, 11, 12}, new int[3] {11,13,12}, new int[3] {11,11,16} };




professions = new Profession[3]
for (int i = 0; i < 3; i++)

    {
        professions[i] = CreateProfession (name[i], description[i], profimages[i], minRequirements[i]);

    }


    for (int i = 0; i < professionNames.Length; i++) //this starts at least one of the loops

    {
        profession[i] = createItem(professionNames[i], professionDescriptions[i], professionImageNames[i], minRequirements[i]);

    }


    //profession01 = createItem("Karate Fighter", "Use hand to hand combat for powerful attacks!", "portrait01");
    //profession02 = createItem("Ninja Fighter", "Use high stealth and sneak attacks to suprize you enemies!", "portrait02");
    //profession03 = createItem("Samurai Fighter", "Use your wisdom to reverse attacks with 2x the power!", "portrait03"); 


    for (int i = 0; i < imagesNames.Length; i++) //creates a for loop for the images
    {
        images[i] = CreateSprite(imagesNames[i]); //makes it so the images come from CreatSprite
        //array     
    }

     portraitImage.sprite = images[currentImage]; //renders the current images


profession.characterManager = this;

for (in i = 0; i < minRequirement.Length; i++) {

    profession.requirements [i] = profession.CreateRequirement { Attribute [i], minRequirement[i];
}

return profession;

}

2 个答案:

答案 0 :(得分:0)

您在此行中遗漏了;

professions = new Profession[3]

这些类型的错误应该非常明显,通常你总是想检查上面的行第一个错误,错过分号可能是最常见的编程&#34;错误&#34在IDE突出显示错误行之前,情况要糟糕得多。

Lazy Coder指出的第二个错误是在最后一个for循环中缺少t

for (int i = 0; i < minRequirement.Length; i++)

同样,通过审查错误应该很明显。它应该是错误&#34;标识符; &#39;在&#39;是关键字&#34;

答案 1 :(得分:0)

 // Use this for initialization
void Start()
{
    string[] imagesNames = new string[3] { "portrait01", "portrait02", "portrait03" };
    //images [0] = CreateSprite ("portrait01");
    //images[1] = CreateSprite ("portrait02");
    //images[2] = CreateSprite ("portrait03");
    string[] professionNames = new string[3] {"Karate fighter", "Ninja Figher", "Samurai Fighter"};
    string[] professionDescriptions = new string[3] { "Use hand to hand combat for powerful attacks! Req: Strength = 13 and Special = 10", 
        "Use high stealth and sneak attacks to suprize you enemies! Req: Speed = 15 or Strength = 9", 
        "Use your wisdom to reverse attacks with 2x the power! Req: Wisdom = 14 or Special = 13" };

    string[] professionImageNames = new string[3] { "profession01", "profession02", "profession03"};
    int[] [] minRequirements = { new int [3] {11, 11, 12}, new int[3] {11,13,12}, new int[3] {11,11,16} };




professions = new Profession[3]  //WERE IS THE PROFESSION CLASS CREATED?
//PROFESSIONS NEEDS TO HAVE A TYPE var profession = new Proffession[3];
for (int i = 0; i < 3; i++)

    {
        professions[i] = CreateProfession (name[i], description[i], profimages[i], minRequirements[i]); //CreateProffession is not implemented on your example, the signature could be like public Profession CreateProfession(string name, string description des, string proofImage, int[] minRequirement)

    }


    for (int i = 0; i < professionNames.Length; i++) //this starts at least one of the loops

    {
        //DID YOU MEAN professions
        profession[i] = createItem(professionNames[i], professionDescriptions[i], professionImageNames[i], minRequirements[i]);

    }


    //profession01 = createItem("Karate Fighter", "Use hand to hand combat for powerful attacks!", "portrait01");
    //profession02 = createItem("Ninja Fighter", "Use high stealth and sneak attacks to suprize you enemies!", "portrait02");
    //profession03 = createItem("Samurai Fighter", "Use your wisdom to reverse attacks with 2x the power!", "portrait03"); 


    for (int i = 0; i < imagesNames.Length; i++) //creates a for loop for the images
    {
        //DID YOU MEAN imagesNames
        images[i] = CreateSprite(imagesNames[i]); //makes it so the images come from CreatSprite
        //array     
    }

     portraitImage.sprite = images[currentImage]; //renders the current images  //WHERE IS currentImage created?


profession.characterManager = this;

//FOR is for(int i=0 , int with t
for (in i = 0; i < minRequirement.Length; i++) {

    profession.requirements [i] = profession.CreateRequirement { Attribute [i], minRequirement[i];
}

return profession;

}