Solved Help With Cycling Through List

Discussion in 'Plugin Development' started by ReadySetPawn, Jul 26, 2014.

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

    ReadySetPawn

    Here's my code:

    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){

    @Override
    public void run() {
    for (int tip = 1; tip > 5; tip++){
    if (tip == 5){
    tip = 1;
    }
    if (tip == 1){
    BarAPI.setMessage(ChatColor.GREEN + prefix + " " + ChatColor.GOLD + tip1);
    Bukkit.getServer().broadcastMessage(ChatColor.GREEN + prefix + " " + ChatColor.GOLD + tip1);
    }
    if (tip == 2){
    BarAPI.setMessage(ChatColor.GREEN + prefix + " " + ChatColor.GOLD + tip2);
    Bukkit.getServer().broadcastMessage(ChatColor.GREEN + prefix + " " + ChatColor.GOLD + tip2);
    }
    if (tip == 3){
    BarAPI.setMessage(ChatColor.GREEN + prefix + " " + ChatColor.GOLD + tip3);
    Bukkit.getServer().broadcastMessage(ChatColor.GREEN + prefix + " " + ChatColor.GOLD + tip3);
    }
    if (tip == 4){
    BarAPI.setMessage(ChatColor.GREEN + prefix + " " + ChatColor.GOLD + tip4);
    Bukkit.getServer().broadcastMessage(ChatColor.GREEN + prefix + " " + ChatColor.GOLD + tip4);
    }
    if (tip == 5){
    BarAPI.setMessage(ChatColor.GREEN + prefix + " " + ChatColor.GOLD + tip5);
    Bukkit.getServer().broadcastMessage(ChatColor.GREEN + prefix + " " + ChatColor.GOLD + tip5);
    }


    }
    }

    }, 20, 20 * delay);

    I have everything registered, the .yml's are good, etc. The problem is this piece of code.

    I want the system to display tips in order from 1 - 5 and when it gets to five, it restarts back to one.

    Thanks :)
     
  2. Offline

    Giraffeknee

  3. Offline

    k9rosie

    that's because you have this loop in a repeating task
     
  4. Offline

    ReadySetPawn

    k9rosie

    How do I make it cycle through in a repeating task then?
     
  5. Offline

    k9rosie

    how often is your task supposed to repeat?
     
  6. Offline

    ReadySetPawn

    k9rosie

    Well it's configurable in seconds but I usually keep it at 300 seconds (5 minutes).
     
  7. Offline

    k9rosie


    nevermind my last comment. is the loop restarting back at one the problem you're having? or is that what you want it to do
     
  8. Offline

    ReadySetPawn

    k9rosie

    When I log onto the server, it doesn't display any text. And I know the methods that display the text work because they worked when I used the random method.

    I actually found part of the problem. I accidentally had "<" rather than ">". But now it just spams all the messages every 5 minutes =/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  9. Offline

    k9rosie


    well that's what you programmed it to do. what are you trying to do?
     
  10. Offline

    MrlolDestructo

    To do tips, you wouldn't use a for loop. If you use a for loop, it would just consistently spam it, as there is no delay, and since it is inside a repeating task, it would just get very awkward. What you would want to do is outside of the run method, create the tip variable, and then check which number it is inside the run statement. Then you would want to do whatever, and if it goes to 5, set it back to 1. Then just make the delay however long you want in ticks.
     
  11. Offline

    ReadySetPawn

    Alright I fixed it now thanks to the help of you two :D

    Thanks <3
     
Thread Status:
Not open for further replies.

Share This Page