setExp Calculation Problems

Discussion in 'Plugin Development' started by danthonywalker, Aug 6, 2013.

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

    danthonywalker

    I am having trouble manipulating my experience bar. Well, not so much so that I can't change it, but for something I can't figure out my calculations keep failing.

    Here's what I have so far:
    Code:
    System.out.print("Current: " + player.getExp());
    System.out.print("Calculation: " + (player.getExp() - (5 / player.getExpToLevel())));
    System.out.print("Equation: " + 5 / player.getExpToLevel());
    System.out.print("player.getExpToLevel(): " + player.getExpToLevel());
    player.setExp(player.getExp() - (5 / player.getExpToLevel()));
    Say we have a scenario where the experience bar is full and at level 0. This puts the player.getExp() at 1. So this is what the console outputs:
    Code:
    Current: 1.0
    Calculation: 1.0
    Equations: 0
    player.getExpToLevel(): 17
    Which I find strange because 5 / 17 should be .294117... not 0. Can someone tell me what I am doing wrong to make the equation 5 / player.getExpToLevel to keep printing out 0?
     
  2. Offline

    CubieX

    Cast this expression to float. Otherwise it will be handled like an integer and truncated to 0.
     
Thread Status:
Not open for further replies.

Share This Page