【问题标题】:Unexpected Symbol for Project项目的意外符号
【发布时间】:2015-12-15 19:38:40
【问题描述】:

我无法理解为什么我的代码存在“意外符号”。我正在为一个项目使用 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;

}

【问题讨论】:

  • 首先,这个professions = new Profession[3] 需要一个;
  • 另外,您的最后一个 for 循环在“int i = 0;”中缺少“t”
  • 你的变量名不一致

标签: c# for-loop


【解决方案1】:

您在这一行缺少;

professions = new Profession[3]

这些类型的错误应该很明显,通常你总是想检查第一个错误上面的行,缺少分号可能是最常见的编程“错误”,它是在 IDE 突出显示的错误行之前要糟糕得多。

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

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

再次,从检查错误中应该很明显。它应该给出一个错误 "Identifier expected; 'in' is a keyword"

【讨论】:

    【解决方案2】:
     // 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;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 2013-01-16
      • 2023-03-18
      • 2014-07-15
      相关资源
      最近更新 更多