Solved for loop not working in run()/thread

Discussion in 'Plugin Development' started by tryy3, Aug 4, 2013.

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

    tryy3

    Hi, I been trying to code my first plugin for the past 3 days or so, I come to the part where I am completely stuck and not sure what I done wrong!

    The for loop is outputting the messages: testings: 0 and testing: 0
    The code is:
    Code:java
    1. for (int rawr = 0; rawr <= c; rawr++){
    2. sender.sendMessage("testings: " + rawr);
    3.  
    4. int test = rawr--;
    5. sender.sendMessage("testing: " + test);
    6. }



    I tried testing back and forth, but I can't find why the variables don't increase!
    The for loop is inside a switch, which is inside a run(), which is inside a thread
    Code:java
    1. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { code.... }, 0L, 20L
    which is inside a onCommand()

    What did I do wrong?
     
  2. Offline

    savagesun

    Try replacing test = rawr--; to test = rawr - 1;

    -- is the same as -= so you've been reducing the value of rawr by 1 each time you run the for loop causing it to remain at 0.
     
  3. Offline

    tryy3

    :confused: that works... but before the for loop wasn't working as in it was just looping continuously, oh well it works now, thanks :p
    I read the edit... oh... thanks!
     
Thread Status:
Not open for further replies.

Share This Page