Solved 2 xp bars + Invalid assignment operator

Discussion in 'Plugin Development' started by mug561, Aug 19, 2014.

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

    mug561

    2 questions about my code: a. it works, but after a certain amount of time it creates More than 1 xp bar.. so clearly its not stopping itself after 0.98.. how can i fix this?
    b. for the line: for(xp < 1F;;xp = 0.98F), i get a invalid assignmentOperator error, why is this? in order to get this to work, i changed "<" to "=" and i got the double xp bar
    heres the code that im 90% sure is causing the bug:
    Code:java
    1. float xp = player1.getExp();
    2. for(xp < 1F;;xp = 0.98F){
    3. player1.setExp((float) (player1.getExp() + 0.01));
    4. Thread.sleep(500);

    no errors in console, just double xp bar.


    sorry imma noob...
     
  2. Offline

    Tecno_Wizard

  3. Offline

    mug561


    by double xp bar i mean theres a second, cutoff xp bar on the right side if the main xp bar.

    EDIT: derp.. i thought it went initialization;increment; THAN termination;
     
  4. Offline

    Tecno_Wizard

    mug561, That in all likelihood is a Bukkit bug, not you. Read the link I put above to fix your for loop as well.
    Also, being a noob is fine, we are were at one point. I've only been Bukkit coding for a half year.

    Code:java
    1. for(int xp = player1.getExp(); xp<=.98; xp++)
    2. {
    3. player1.setExp((float) (player1.getExp() + 0.01));
    4. }
    5.  

    Is this what you're looking for?
     
  5. Offline

    mug561

    Tecno_Wizard one more thing.. what would i put for the termination of the for loop? i tried xp = (float) 0.99;, but it says cannot convert from boolean to float.....

    yes thanks, just changed int to float...

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

    Tecno_Wizard

    mug561, The way the loop that I posted is, it will terminate when xp=.99
    for loops are set up this way

    for(initializing of variable; checking to see if variable<-- still fills parameters; increment variable)
    When the variable no longer fulfills the second statement, the loop terminates;
    To clarify, the second statement needs to return a Boolean. true means it will continue, false stop.
    Again, http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
     
  7. Offline

    mug561

    Tecno_Wizard k i got it all to work the way i needed, fixed the double xp bar by adding a
    if(player1.getExp() >= 1F)
    {player1.setExp(1F);}
    in my run...
    thanks for ur halp :D
     
  8. Offline

    Tecno_Wizard

    mug561, I would report a bug that when a number larger than 1 is passed into that method, a second XP bar shows up. I really don't think it should be doing that.
     
Thread Status:
Not open for further replies.

Share This Page