Percentages In Java?

Discussion in 'Spigot Plugin Development' started by sirderp, Jun 26, 2016.

  1. Hello everyone. I am fairly new to java so please bare with me. I found a template online for percentages that i'm currently using for my boss plugin (mob drops is the thing I need fixed here).
    Here is some of the code:
    Code (Text):
          if (x -= 4.0D < 0.0D)
            dropItem(loc, new ItemBuilder(Material.MOB_SPAWNER, 91).getItem());
    The if (x -= 4.0D < 0.0D) gives me an eclipse error (The operator -= is undefined for type(s) double, boolean.), I guess what I found online was old, was wondering if any of you can give me a quick fix / answer to this?

  2. Please just learn java first.
    • Optimistic Optimistic x 3
    • Winner Winner x 2
  3. Choco


    That is valid Java. He just made a simple mistake
    Put "x -= 4.0D" in parenthesis
    • Agree Agree x 8
  4. this is the short form for
    Code (Text):
    x = x - 4;
    which will reduce the value of the variable
    if that is not what you realy want use
    Code (Text):
     if (x - 4 < 0)
  5. Thank you, unlike that StalexDev guy hes no help :p
    #5 sirderp, Jun 26, 2016
    Last edited: Jun 26, 2016
    • Like Like x 1
  6. StalexDev said the right thing. I learned Java after making a few help posts and never made anymore.
    • Funny Funny x 3
    • Agree Agree x 1
  7. Yeah I realize that he's right, but he's not helping :p
  8. Not even a typo? :eek:

    But really, claiming to never make a mistake again is just unrealistic.
    • Agree Agree x 2
  9. I mean't needing to make help posts. Anyways I was wrong in this post. @sirderp, sorry.
    • Like Like x 1
  10. So now you are bashing on me when I'm just advising you the right thing. I am helping you by telling you to learn Java first before jumping into something like the Spigot API but whatever...
  11. -= would be a bad operator here anyhow, you're decrementing the x value by 4 so any use afterward will also be reduced by 4.

    As for percentages that's not really an idealistic approach anyhow, but it depends on surrounding code.
    • Agree Agree x 2