0

这是 Joachim 解决方案后的代码:

http://codepad.org/AB2gu59t

这是我现在得到的错误:

Scripts\OHDHerblaw.java:109:错误:未定义标签:label1084 if (getInventoryCount(new int[] { this.Herb }) == 0) if (getInventoryCou nt(new int[] { this.Unfinished }) == 0 ) if (getInventoryCount(new int[] { this.Idenified }) == 0) break label417; if (getInventoryCount(new int[] { this.Vials }) != 0) if (getInventoryCount(new int[] { this.Identified }) != 0) { if (getIn ventoryCount(new int[] { this.Vials }) != 0) if (getInventoryCount(new int[] { t his.Identified }) != 0) break label1084; if (getInventoryCount(new int[] { this.Unfinished }) != 0)

Scripts\OHDHerblaw.java:110:错误:未定义标签:label1084 break label1084;}

Scripts\OHDHerblaw.java:201:错误:未定义标签:label1391 break label1391;

Scripts\OHDHerblaw.java:202:错误:未定义标签:label1706 if (getInventoryCount(new int[] { this.Vials }) != 0) if (getInventoryCo unt(new int[] { this.Identified }) != 0 ) { if (getInventoryCount(new int[] { thi s.Vials }) != 0) if (getInventoryCount(new int[] { this.Identified }) != 0) 打破 label1706; if (getInventoryCount(new int[] { this.Unfinished }) != 0)

Scripts\OHDHerblaw.java:203: 错误: 未定义标签: label1706 break label1706; }

5 个错误

我不确定如何定义标签。

经过一番挣扎,我让它工作了。如果有人感兴趣,这是修改后的代码。

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class OHDHerblaw extends Script {

   int Herb;
   int Identified = 0;
   int Unfinished;
   int Ingrediant;
   int potsMade;
   int Vials = 464;
   int[] POTARRAY = new int[]{222, 474, 477, 480, 483, 486, 489, 492, 495, 498, 566, 569, 570};
   int[] UNIDARRAY = new int[0];
   int[] IDARRAY = new int[0];
   boolean onlyId = false;
   boolean idHerbs = false;
   boolean isMixing = false;
   boolean unfinishedOnly = false;


   public OHDHerblaw(Extension var1) {
      super(var1);
   }

   public void init(String var1) {
      String[] var2 = var1.trim().replaceAll(" ", "").split(",");
      if(!var2[0].equals("")) {
         this.Herb = Integer.parseInt(var2[0]);
         if(this.Herb <= 443) {
            if(this.Herb == 165 || this.Herb >= 435 && this.Herb <= 443) {
               this.idHerbs = true;
               this.unfinishedOnly = false;
               if(this.Herb == 165) {
                  this.Identified = 444;
                  this.Unfinished = 454;
               } else if(this.Herb > 165) {
                  this.Identified = this.Herb + 10;
                  this.Unfinished = this.Herb + 20;
               }
            }
         } else if(this.Herb >= 444) {
            if(this.Herb >= 444 && this.Herb <= 453) {
               this.Herb -= 10;
               this.Identified = this.Herb + 10;
               this.Unfinished = this.Herb + 20;
               this.idHerbs = false;
               this.unfinishedOnly = false;
            } else if(this.Herb >= 454 && this.Herb <= 463) {
               this.Herb -= 20;
               this.Identified = this.Herb + 10;
               this.Unfinished = this.Herb + 20;
               this.idHerbs = false;
               this.unfinishedOnly = true;
            }
         } else {
            System.out.println("That\'s is not a valid Herb Id...");
            this.stopScript();
         }
      }

      if(!var2[1].equals("")) {
         this.Ingrediant = Integer.parseInt(var2[1]);
         if(this.Ingrediant != 270 && this.Ingrediant != 473 && this.Ingrediant != 220 && this.Ingrediant != 219 && this.Ingrediant != 471 && this.Ingrediant != 469 && this.Ingrediant != 472 && this.Ingrediant != 501) {
            System.out.println("No ingredient selected. We will not be making full potions...");
            this.Ingrediant = 0;
            this.isMixing = false;
         } else {
            this.isMixing = true;
         }
      }

      if(this.unfinishedOnly && !this.isMixing) {
         System.out.println("Not possible, please re-check script setup...");
         this.stopScript();
      }

   }

   public int main() {

      if(this.getFatigue() >= 90) {
         this.useSleepingBag();
         return this.random(800, 1000);
      } else {
         if(!this.onlyId) {
            int[] var1;
            if(this.isMixing) {
               if(this.idHerbs && this.getInventoryCount(new int[]{this.Herb}) > 0) {
                  this.useItem(this.getInventoryIndex(new int[]{this.Herb}));
                  return this.random(200, 350);
               }

               if(this.getInventoryCount(new int[]{this.Identified}) > 0 && this.getInventoryCount(new int[]{this.Vials}) > 0 && this.getInventoryCount(new int[]{this.Herb}) == 0) {
                  this.useItemWithItem(this.getInventoryIndex(new int[]{this.Identified}), this.getInventoryIndex(new int[]{this.Vials}));
                  return this.random(200, 350);
               }

               if(this.getInventoryCount(new int[]{this.Ingrediant}) > 0 && this.getInventoryCount(new int[]{this.Unfinished}) > 0) {
                  this.useItemWithItem(this.getInventoryIndex(new int[]{this.Ingrediant}), this.getInventoryIndex(new int[]{this.Unfinished}));
                  return this.random(500, 600);
               }

               if(this.getInventoryCount(new int[]{this.Herb}) == 0 && this.getInventoryCount(new int[]{this.Unfinished}) == 0 && this.getInventoryCount(new int[]{this.Identified}) == 0 || this.getInventoryCount(new int[]{this.Vials}) == 0 || this.getInventoryCount(new int[]{this.Identified}) == 0 || (this.getInventoryCount(new int[]{this.Vials}) == 0 || this.getInventoryCount(new int[]{this.Identified}) == 0) && this.getInventoryCount(new int[]{this.Unfinished}) == 0) {
                  if(this.isQuestMenu()) {
                     this.answer(0);
                     return this.random(2000, 3000);
                  }

                  if(this.isBanking()) {
                     int var2;
                     if(this.unfinishedOnly) {
                        if(this.getInventoryCount(new int[]{this.Ingrediant}) == 0 || this.getInventoryCount(new int[]{this.Unfinished}) == 0) {
                           for(var2 = 0; var2 < this.POTARRAY.length; ++var2) {
                              if(this.getInventoryCount(new int[]{this.POTARRAY[var2]}) > 0) {
                                 this.deposit(this.POTARRAY[var2], this.getInventoryCount(new int[]{this.POTARRAY[var2]}));
                                 return this.random(1250, 1500);
                              }
                           }
                        }

                        if(this.getInventoryCount(new int[]{this.Unfinished}) == 0) {
                           this.withdraw(this.Unfinished, 14);
                           return this.random(1500, 2000);
                        }

                        if(this.getInventoryCount(new int[]{this.Ingrediant}) == 0 && this.getInventoryCount(new int[]{this.Unfinished}) > 0) {
                           this.withdraw(this.Identified, this.getInventoryCount(new int[]{this.Unfinished}));
                           return this.random(1500, 2000);
                        }

                        this.closeBank();
                        return this.random(200, 300);
                     }

                     if(!this.unfinishedOnly) {
                        if(this.getInventoryCount(new int[]{this.Ingrediant}) == 0 || this.getInventoryCount(new int[]{this.Unfinished}) == 0) {
                           for(var2 = 0; var2 < this.POTARRAY.length; ++var2) {
                              if(this.getInventoryCount(new int[]{this.POTARRAY[var2]}) > 0) {
                                 this.deposit(this.POTARRAY[var2], this.getInventoryCount(new int[]{this.POTARRAY[var2]}));
                                 return this.random(1250, 1500);
                              }
                           }
                        }

                        if(this.getInventoryCount(new int[]{this.Unfinished}) > 0) {
                           this.withdraw(this.Ingrediant, this.getInventoryCount(new int[]{this.Unfinished}));
                           this.closeBank();
                           return this.random(2000, 3000);
                        }

                        if(this.getInventoryCount(new int[]{this.Vials}) == 0) {
                           this.withdraw(this.Vials, 14);
                           return this.random(1000, 1500);
                        }

                        if(this.getInventoryCount(new int[]{this.Herb}) == 0 && this.getInventoryCount(new int[]{this.Unfinished}) == 0 && this.getInventoryCount(new int[]{this.Identified}) == 0 && this.idHerbs) {
                           this.withdraw(this.Herb, 14);
                           return this.random(2000, 3000);
                        }

                        if(this.getInventoryCount(new int[]{this.Identified}) == 0) {
                           this.withdraw(this.Identified, 14);
                           return this.random(1000, 1500);
                        }

                        this.closeBank();
                        return this.random(1000, 1500);
                     }
                  }

                  var1 = this.getNpcByIdNotTalk(this.BANKERS);
                  if(var1[0] != -1 && !this.isBanking() && !this.isQuestMenu() && this.getInventoryCount(new int[]{this.Ingrediant}) == 0) {
                     this.talkToNpc(var1[0]);
                     return this.random(3250, 3500);
                  }
               }
            }

            if(!this.isMixing) {
               if(this.idHerbs && this.getInventoryCount(new int[]{this.Herb}) > 0) {
                  this.useItem(this.getInventoryIndex(new int[]{this.Herb}));
                  return this.random(200, 350);
               }

               if(this.getInventoryCount(new int[]{this.Identified}) > 0 && this.getInventoryCount(new int[]{this.Vials}) > 0 && this.getInventoryCount(new int[]{this.Herb}) == 0) {
                  this.useItemWithItem(this.getInventoryIndex(new int[]{this.Identified}), this.getInventoryIndex(new int[]{this.Vials}));
                  return this.random(200, 350);
               }

               if(this.getInventoryCount(new int[]{this.Herb}) == 0 && this.getInventoryCount(new int[]{this.Unfinished}) == 0 && this.getInventoryCount(new int[]{this.Vials}) == 0 && this.getInventoryCount(new int[]{this.Identified}) == 0 || this.getInventoryCount(new int[]{this.Vials}) == 0 || this.getInventoryCount(new int[]{this.Identified}) == 0 || (this.getInventoryCount(new int[]{this.Vials}) == 0 || this.getInventoryCount(new int[]{this.Identified}) == 0) && this.getInventoryCount(new int[]{this.Unfinished}) == 0) {
                  if(this.isQuestMenu()) {
                     this.answer(0);
                     return this.random(2000, 3000);
                  }

                  if(this.isBanking()) {
                     if(this.getInventoryCount(new int[]{this.Herb}) == 0 && this.getInventoryCount(new int[]{this.Unfinished}) == 0 && this.getInventoryCount(new int[]{this.Vials}) == 0 && this.getInventoryCount(new int[]{this.Identified}) == 0 && this.idHerbs) {
                        this.withdraw(this.Herb, 14);
                        return this.random(2000, 3000);
                     }

                     if(this.getInventoryCount(new int[]{this.Unfinished}) > 0) {
                        this.deposit(this.Unfinished, this.getInventoryCount(new int[]{this.Unfinished}));
                        return this.random(200, 300);
                     }

                     if(this.getInventoryCount(new int[]{this.Vials}) == 0) {
                        this.withdraw(this.Vials, 14);
                        return this.random(1000, 1500);
                     }

                     if(this.getInventoryCount(new int[]{this.Identified}) == 0) {
                        this.withdraw(this.Identified, 14);
                        return this.random(1000, 1500);
                     }

                     this.closeBank();
                     return this.random(1000, 1500);
                  }

                  var1 = this.getNpcByIdNotTalk(this.BANKERS);
                  if(var1[0] != -1 && !this.isBanking() && !this.isQuestMenu()) {
                     this.talkToNpc(var1[0]);
                     return this.random(3500, 3750);
                  }
               }
            }
         }

         return this.random(200, 300);
      }
   }
}
4

4 回答 4

2

标签只能在语句之前使用(JLS §14.7)

局部变量声明不是语句(在 JLS 中,它是“块语句”(JLS §14.2),它是语句的超集)。

简单地将您移到标签之前int[] arrayOfInt;的行,您应该会很好:

int[] arrayOfInt;
label417:
if (this.isMixing) {
  ...
于 2012-12-18T14:32:03.260 回答
1

一个标签后面必须跟一个语句。在您的代码中,它后面是一个变量声明,它不是一个语句。

在变量声明后移动标签:

int[] arrayOfInt;

label417:
if (this.isMixing) {
    // ...

顺便说一句,我认为在 Java 代码中使用标签是一种代码气味——这表明代码的设计存在问题。标签就像goto 语句,这是一种臭名昭著的结构,使代码难以理解(它导致意大利面条式代码)。

不要使用标签,而是使用其他控制结构,例如forwhile循环。

于 2012-12-18T14:36:17.407 回答
1

@Joachim 的回答已经确定了。

我只是想解释为什么...

break <label>语句只能分解为当前方法中具有给标签的封闭语句。局部变量声明不能包含break语句。因此label,局部变量声明上的 a 也不能被破坏。

我怀疑您试图使用break <label>C/C++ 语句之类的goto语句。它不是那样工作的。即使那里允许使用标签,您也无法打破它。例如,这同样是错误的:

label: if (i == 1) {
   // so something
}
if (i == 2) {
   break label;  // compilation error
}
于 2012-12-18T14:37:17.390 回答
0

赋值标签有一点不同的语法:

 int i;
 label12: i = 42; // label on the assignment

如果要为标签分配值,则必须先定义它。

在您的情况下,将代码更改为:

if (!this.onlyId)
    {
      int[] arrayOfInt;
      label417:      
      if (this.isMixing)
      {
        if (this.idHerbs) {
          if (getInventoryCount(new int[] { this.Herb }) > 0) {
            useItem(getInventoryIndex(new int[] { this.Herb }));
            return random(200, 350);
          }
        }
于 2012-12-18T14:33:44.667 回答