1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Resolved For Loop not being executed in script?

Discussion in 'Developer Support' started by forgottenape101, Apr 2, 2018.

Tags:
  1. forgottenape101

    Joined:
    Mar 23, 2018
    Messages:
    4
    Likes Received:
    0
    Hello everyone! I'm not an experienced developer for runemate or java for that matter, but I am trying to make a simple open-source script bot that adds up the player's total wealth and tells you it. Simple enough for my first script bot.

    Here's the relevant code:
    Code (Text):
    1.  
    2. if(Bank.open()){
    3.  
    4.     SpriteItem[] items = Bank.getItems().toArray(new SpriteItem[0]);
    5.  
    6.     if(items != null){
    7.  
    8.         System.out.println("Total Items to Count: " + items.length);
    9.  
    10.         for(int i = 0; i == items.length; i++){
    11.  
    12.             int id = items[i].getId();
    13.  
    14.             if(id != 0){
    15.  
    16.                 System.out.println("Looking up price for ID " + id);
    17.  
    18.                 int addwealth = GrandExchange.lookup(id).getPrice();
    19.  
    20.                 if(addwealth > 0) {
    21.  
    22.                     wealth += addwealth;
    23.  
    24.                     System.out.println("Total Wealth: " + wealth);
    25.                 }else{
    26.                     System.out.println("Could not locate price for " + id);
    27.                 }
    28.             }
    29.  
    30.         }
    31.  
    32.     }
    33.  
    34. }
    35.  
    But when I run the bot, it seems to only run this portion of the code, and since it doesn't enter the For loop I imagine, it keeps being validated and executed indefinitely.

    Code (Text):
    1.  
    2. if(Bank.open()){
    3.  
    4.     SpriteItem[] items = Bank.getItems().toArray(new SpriteItem[77]);
    5.  
    6.     if(items != null){
    7.  
    8.         System.out.println("Total Items to Count: " + items.length);
    9.  
    Again, I'm new so my code probably is shite but hey, you gotta start somewhere eh? I can post the full class files if someone needs me to.
     
  2. Best Answer:
    Post #2 by Dark sage, Apr 2, 2018
  3. Dark sage

    Dark sage Misfits

    Joined:
    Nov 21, 2016
    Messages:
    1,333
    Likes Received:
    373
    the issue lies in this line

    "for(int i = 0; i == items.length; i++){"
     
    CuppaJava likes this.

Share This Page

Loading...