Solved Why is this while loop incorrect?

Discussion in 'Plugin Development' started by _Ogle, Mar 27, 2017.

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

    _Ogle

    so I basically want a method that will broadcast a message every 2 minutes for an hour but for some reason it waits the 2 minutes and then broadcasts the message 30 times.
    Code:
           int i = 0;
     while(i<30)
            {
            plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
                public void run()
                {
    
                        Bukkit.broadcastMessage(ChatColor.GOLD +ChatColor.BOLD.toString() +"Remember to type /thanks for free repair coins!");
                      
                  
                }
            }, 2400L);
            i++;
            }
     
  2. Offline

    Zombie_Striker

    @_Ogle
    That is because you are creating 30 tasks and do not change the delay. Multiply the long by I.
     
  3. Offline

    _Ogle

    won't that just make the delay longer and longer? I want to wait 2400 ticks before the loops gets run everytime
     
  4. Offline

    Zombie_Striker

    @_Ogle
    Well, yes. That's what you want. You don't want all the message to happen at the same time. You want them to be spread out by 2 minutes, and multiplying the delay by I will do that.
     
  5. Offline

    _Ogle

    I have no idea how or why this works but it does so ty :)
     
Thread Status:
Not open for further replies.

Share This Page