Countdown timer help

Discussion in 'Plugin Development' started by lrdemolition, Aug 17, 2014.

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

    lrdemolition

    so im trying to make this timer countdown from ten but it wont work.can someone fix it and explain please.

    Code:
        private void pcheck() {
            if(blue.size() + red.size() + green.size() + white.size() > 6 || blue.contains("lrdemolition")){
                Bukkit.getServer().broadcastMessage("gamestart initialized");
                this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                    int time = 10;
                    public void run() {
                        int time = time - 1;
                        Bukkit.getServer().broadcastMessage("time =" + time);
                        if(time == 0){
                            // teleport players in the 4 arrays and stop timer and reset it countdown
                        }
                    }
                  }, 0L, 20L);// 60 L == 3 sec, 20 ticks == 1 sec
            }
        }
     
  2. Offline

    AoH_Ruthless

    lrdemolition
    "fix it and explain please":
    • You tell us nothing about what is actually wrong
    • Any errors?
    • What is time printing as? How can it countdown fully when you never actually cancel the countdown?
    We cannot fix it because you are just throwing us code without any explanation. While the code is useful in aiding you, it is not a substitute for a well-written problem explanation.
     
  3. Offline

    lrdemolition

    AoH_Ruthless
    on line 5 under time theres a red error stating "the local variable time may not have been initialized"

    also when the plugin runs on the server nothing happens when im in the blue team except it saying gamestart initialized

    and what do u mean by ur 3rd bullet point?

    AoH_Ruthless

    can someone show me how a very simple countdown method would run

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

    KaitouKidFTW

  5. Offline

    lrdemolition

    KaitouKidFTW
    i replaced
    Code:
        private void pcheck() {
            if(blue.size() + red.size() + green.size() + white.size() > 6 || blue.contains("lrdemolition")){
                Bukkit.getServer().broadcastMessage("gamestart initialized");
                this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                    int time = 10;
                    public void run() {
                        time --;
                        Bukkit.getServer().broadcastMessage("time =" + time);
                        if(time == 0){
                            // teleport players in the 4 arrays and stop timer and reset it countdown
                        }
                    }
                  }, 0L, 20L);// 60 L == 3 sec, 20 ticks == 1 sec
            }
        }


    it does not work still, i need it just to count down from 10, then stop the task
     
  6. Offline

    KaitouKidFTW

  7. Offline

    SuperOmegaCow

    lrdemolition
    Try this:
    Code:java
    1. private void pcheck() {
    2. if(blue.size() + red.size() + green.size() + white.size() > 6 || blue.contains("lrdemolition")){
    3. Bukkit.getServer().broadcastMessage("gamestart initialized");
    4. int time = 10;
    5. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    6. public void run() {
    7. time --;
    8. Bukkit.getServer().broadcastMessage("time =" + time);
    9. if(time == 0){
    10. // teleport players in the 4 arrays and stop timer and reset it countdown
    11. }
    12. }
    13. }, 0L, 20L);// 60 L == 3 sec, 20 ticks == 1 sec
    14. }
    15. }
     
  8. Offline

    lrdemolition

    can someone explain to me why the
    code does not run

    does time need to be a global variable?

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

Share This Page