Solved Problems with if statement and the Modulo (%) Operator

Discussion in 'Plugin Development' started by GeekyMe97, Oct 9, 2012.

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

    GeekyMe97

    In my plugin, I have a kill counter, and I want to make it so if your kills amounts to a multiply by 25, then broadcast it.
    What I have so far doesn't seem to work:
    Code:JAVA
    1.  
    2. // If the player's kills amounts to a multiple of 25, broadcast it
    3. if (kills % 25 == 0) {
    4. GeneralMethods.sendMessageToAllPlayers(
    5. ChatColor.BLUE + killer + " has killed a total of " + kills + " zombies!", plugin);
    6. }
    7.  

    Though, this isn't working and I don't know why.
    I know that this "if statement" gets executed and that the sendMessageToAllPlayers method works.

    I'm quite sure that "(kills%25 == 0)" is the problem.
    Anybody knows where I can read more about that specific topic?

    Help would be appreciated :)

    EDIT;
    When I say it's "not working", I mean nothing happens, just like it would always return false. No errors or anything.
     
  2. Offline

    LukeSFT

    For what do you need this % ??
     
  3. Offline

    LukeSFT

  4. LukeSFT So what's your question then? He needs the % to get the modulo of kills to check if it's 0 to see if the number is a multiply of 25 (which is exactly what he told in the first post).
     
  5. Offline

    LukeSFT

    I don't know it myself.

    sorry
     
  6. Offline

    gomeow

    Yes, they way he set up the code, it checks if it divides evenly with 25
     
  7. Offline

    GeekyMe97

    Changed it from 25 to 20 and now it seems to work :S
    Think I read somewhere that the number has to be even or something~
     
  8. GeekyMe97 I don't think the numbers have to be even and it would still be good to see what kills % 25 shows when kills is a multiply of 25. So why don't you debug? :(
     
  9. Offline

    gamerzap

    Yeah, I'm pretty sure it can be odd. And even if it has to be even, you could check if kills*2 % 50 == 0.
     
    gomeow likes this.
  10. Offline

    QuantumDev

    Try putting each part in parentheses, seems to help me when my modulo doesn't want to work:

    Code:
    if (((kills % 25) == 0)) {
     
    gamerzap likes this.
Thread Status:
Not open for further replies.

Share This Page