Solved Scheduler only takes final variables

Discussion in 'Plugin Development' started by nuclearmissile, Dec 25, 2014.

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

    nuclearmissile

    I'm having issues because the scheduler will only take final variables, which cannot be affected from inside the method. Is there a way I can have the method containing the scheduled task create a variable that can be affected by the scheduled event?
     
  2. Offline

    teej107

  3. Offline

    mythbusterma

    @nuclearmissile

    It is an anonymous inner class. There are numerous ways around this, the easiest being what Teej suggested above, although you can also copy it into the class.
     
  4. Offline

    nuclearmissile

    @mythbusterma @teej107

    Ok I figured it out on my own, sorry to bother you guys, I feel kind of dumb now.

    Also mythbusterma, what Teej suggested was not the easiest way to do it. The easiest way was to slip it in the runnable but still outside the run method, like so:

    Code:
    final int taskID = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                int step = 0;
                public void run(){
    Thanks for the help anyway guys, it's nice to know people still care about Bukkit even after the drama.
     
  5. Offline

    teej107

    Yeah...
     
  6. Offline

    nuclearmissile

    @teej107 If that's what he meant, why did he say your way was the easiest? With that I literally had to just put the declaration somewhere else, and I've had no problems since.
     
  7. Offline

    mythbusterma

    @nuclearmissile

    Because it's much easier to run into inconsistencies, and more difficult to spot them.
     
Thread Status:
Not open for further replies.

Share This Page