Solved For-loop bug

Discussion in 'Plugin Help/Development/Requests' started by imsanta, Feb 16, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    imsanta

    I've tried to use a for-loop to go through all of the shops display the corresponding material and price. The void to start this is:
    Code:
        private void NewGUI(Player p, int shopID) {
        inv = Bukkit.createInventory(null, 27, "§a§lShop " + shopID);
        for(int i = 0; i < shops[shopID].length; i++)
        {
            i = shops[shopID].length - 1;
            if (shops[shopID][i] != null)
            {
              if (sellPrice[shopID][i] > 0)
              {
                inv.setItem(shopID, new CustomItem(shops[shopID][i], "", Arrays.asList("§4Right click to Buy (§1$" + buyPrice[shopID][i] + "§4)", "§4Left click to Sell (§1$" + sellPrice[shopID][i] + "§4)")));
              } else {
                inv.setItem(shopID, new CustomItem(shops[shopID][i], "", Arrays.asList("§4Right click to Buy (§1$" + buyPrice[shopID][i] + "§4)", "§4You can't sell this item.")));
              }
            }
        }
        inv.setItem(26, new CustomItem(Material.GOLD_INGOT, "§6Balance: $" + (int) econ.getBalance(p) ,Arrays.asList("§4Click to Exit!")));
        p.openInventory(inv);
        }
    
    The output for the loop is weird like so:
    Code:
    [18:27:21 INFO]: 0
    [18:27:21 INFO]: 1
    [18:27:21 INFO]: 18
    [18:27:21 INFO]: 19
    [18:27:21 INFO]: 20
    [18:27:21 INFO]: 21
    [18:27:21 INFO]: 22
    [18:27:21 INFO]: 23
    [18:27:21 INFO]: 24
    [18:27:21 INFO]: 25
    [18:27:21 INFO]: 0
    [18:27:21 INFO]: 1
    [18:27:21 INFO]: 2
    [18:27:21 INFO]: 3
    [18:27:21 INFO]: 4
    [18:27:21 INFO]: 5
    [18:27:21 INFO]: 6
    [18:27:21 INFO]: 7
    [18:27:21 INFO]: 8
    [18:27:21 INFO]: 9
    [18:27:21 INFO]: 10
    [18:27:21 INFO]: 11
    [18:27:21 INFO]: 12
    [18:27:21 INFO]: 13
    [18:27:21 INFO]: 14
    [18:27:21 INFO]: 15
    [18:27:21 INFO]: 16
    [18:27:21 INFO]: 17
    [18:27:21 INFO]: 18
    [18:27:21 INFO]: 19
    [18:27:21 INFO]: 20
    [18:27:21 INFO]: 21
    [18:27:21 INFO]: 22
    [18:27:21 INFO]: 23
    [18:27:21 INFO]: 24
    [18:27:21 INFO]: 25
    
    Edit: fixed.
     
    Last edited: Feb 16, 2015
Thread Status:
Not open for further replies.

Share This Page