项目的意外符号

本文关键字:符号 意外 项目 | 更新日期: 2023-09-27 18:26:58

我很难理解为什么我的代码中存在"意外符号"。我正在为一个项目使用for循环,这几行代码给我带来了问题。我猜这与没有把括号/分号放在某个地方有关,但我不知道它会在哪里。我能得到一些帮助来确定我需要在哪里纠正这个错误吗?在此处输入图像描述

在此处输入图像描述

这是存在错误的完整代码

 // 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;
}

项目的意外符号

您在以下行中缺少一个;

professions = new Profession[3]

这些类型的错误应该非常明显,通常你总是想检查上面的行第一个错误,缺少分号可能是最常见的编程"错误",在IDE突出显示错误行之前情况更糟。

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

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

同样,从审查错误中应该可以明显看出。它应该给出一个错误"需要标识符;'in'是关键字"

 // 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;
}