Solved Stuck in an infinite loop.

Discussion in 'Plugin Development' started by Alshain01, Sep 23, 2013.

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


    I'm really stuck in an infinite loop, or what appears to be one. I'm trying to make a help command that mimics Bukkit help. It has "groups" which are like plugins in Bukkit help and "flags" which are like commands. For some reason this while loops is locking up the server and for the life of me I can't figure out why. I'm working with lists, "groupNames" and "combinedHelp" were created earlier but that appears to be working based on my debug output. Any help is of course appreciated.

    1. // Find the start position in the array of names
    2. int position = ((page - 1) * 9) - 1;
    3. if(position < 0) { position = 0; }
    4. Flags.instance.Debug("Starting Position: " + position);
    6. // Output the results
    7. while (position < combinedHelp.size()); {
    8. if(groupNames.contains(combinedHelp.get(position))) {
    9. Flags.instance.Debug("Showing Group Name: " + combinedHelp.get(position));
    10. sender.sendMessage(combinedHelp.get(position));
    11. } else {
    12. Flags.instance.Debug("Showing Flag Help: " + combinedHelp.get(position));
    13. sender.sendMessage(Message.HelpTopic.get()
    14. .replaceAll("<2>", combinedHelp.get(position))
    15. .replaceAll("<4>", registrar.getFlag(combinedHelp.get(position)).getDescription()));
    16. }
    18. if(++linecount == 9) {
    19. Flags.instance.Debug("Page is full, exiting.");
    20. return true;
    21. }
    22. position++;
    23. }
    24. Flags.instance.Debug("Reached end of list");
    25. return true;

    Debug Output:

    2013-09-23 17:26:37 [INFO] Alshain01 issued server command: /flag help
    2013-09-23 17:26:37 [INFO] [Flags] DEBUG: Groups: 5
    2013-09-23 17:26:37 [INFO] [Flags] DEBUG: Flags: 68
    2013-09-23 17:26:37 [INFO] [Flags] DEBUG: Total Help Entries: 73
    2013-09-23 17:26:37 [INFO] [Flags] DEBUG: Total Pages: 9
    2013-09-23 17:26:37 [INFO] [Flags] DEBUG: Requested Page: 1
    2013-09-23 17:26:37 [INFO] [Flags] DEBUG: Starting Linecount: 1
    2013-09-23 17:26:38 [INFO] [Flags] DEBUG: Starting Position: 0
  2. Offline


    Does linecount get reset after this method executes? Perhaps maybe linecount should be a local variable that's declared before the while loop, thus you wouldn't need to reset it afterwards?

    Also, consider changing it from a while loop to a for loop since you know the number of iterations you're going to do.
    Alshain01 likes this.
  3. Offline


    It is initialized just a few lines above where I snipped it. It starts at 0 and is incremented only if it is the first page (because I display a usage line like Bukkit... i.e. "Use /help [n]... yadda yadda". That's why the debug shows it at 1 when it starts.
  4. Offline


    Oh, duh, you have an extra semicolon right after your while loop parameters.
    (The "duh" is directed at me for not seeing it sooner)
    Alshain01 likes this.
  5. Offline


    I could try making that linecount >= 9, but it's not really the control variable anyway. It just marks a premature exit.


    that must be it.

    Beautiful. Just need to dress up those groups a bit and it will be perfect.

    Thanks so much, I swear I stared at that for hours. Can't believe I didn't see that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page