Solved Counting up within loop

Discussion in 'Plugin Development' started by nick6899, Dec 20, 2018.

Thread Status:
Not open for further replies.
  1. Hey guys, I'm having a small issue. I need 2 integers to increase, one starting at 0 and increasing to 19 and the other to start at 1 and increase to 18.

    Heres what I have so far, I know this is incorrect but hopefully shows what I'm trying to achieve.
    Code:
                                for (int i = 0; i <=19; i++) {
                                    for (int i2 = 1; i2<=18; i2++) {
                                    try {
                                        Player friend = Bukkit.getPlayer(friends.getOnlineList().get(i));
                                        PlayersTab.set(0, i2, new TextTabItem(friend.getName(), 0, Skins.getDot(ChatColor.GREEN)));
                                    }catch(IndexOutOfBoundsException e) {
                                        PlayersTab.set(0, i2, Blank);
                                     }
                                }
                            }
    This just spazzes my name on tab do to the sheer amount of looping.
    Any ideas?
     
    Last edited: Dec 21, 2018
  2. Offline

    timtower Administrator Administrator Moderator

    @nick6899 Second loop is using i instead of i2
     
  3. @timtower, Thanks, but it’s still just spazzing out, is there a better way to do this?
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. I need 2 integers to increase, one starting at 0 and increasing to 19 and the other to start at 1 and increase to 18.

    @timtower

    The only way I know to do that is the way I’ve posted above, unfortunately this runs my try statement 342 times

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 21, 2018
  6. Offline

    timtower Administrator Administrator Moderator

    @nick6899 That is what the code is doing isn't it?
    So what exactly is not how you want it?
     
  7. Thanks @timtower, I just ended up kinda rigging it to get it to do what I needed, if you have any suggestions let me know.

    Code:
                                for (int i = 0; i <=19; i++) {
                                    try {
                                        Player friend = Bukkit.getPlayer(friends.getOnlineList().get(i));
                                        if (i == 19) {
                                            PlayersTab.set(0, i, new TextTabItem(friend.getName(), 0, Skins.getDot(ChatColor.GREEN)));
                                            }else if (i < 19 ) {
                                            PlayersTab.set(0, i + 1, new TextTabItem(friend.getName(), 0,   Skins.getDot(ChatColor.GREEN)));
                                            }
                                        PlayersTab.set(0, i + 1, new TextTabItem(friend.getName(), 0, Skins.getDot(ChatColor.GREEN)));
                                    }catch(IndexOutOfBoundsException e) {
                                        if (i == 19) {
                                        PlayersTab.set(0, i, Blank); //Blank Template
                                        }else if (i < 19 ) {
                                            PlayersTab.set(0, i + 1, Blank); // Blank Template
                                        }
                                     }
                            }
     
Thread Status:
Not open for further replies.

Share This Page