vladbuff Posted August 29 Share Posted August 29 (edited) Currently using this equation with my logic being that 60 minutes / time elapsed * experienced gained will equate to the correct experience per hour and in my script i use this equation to represent that public void onStart() { startingStrengthEXP = getSkills().getExperience(Skill.STRENGTH); startTime = System.currentTimeMillis(); } int currentStrengthEXP = getSkills().getExperience(Skill.STRENGTH); final long runTime = System.currentTimeMillis() - startTime; (3600000 / runTime) * (currentStrengthEXP-startingStrengthEXP) and this works up until about the first 15 minutes and i notice the math starts to go under and it becomes very obvious at 20 minutes were i was able to do the math in my head and know that it was 50% what the correct amount of experience per hour should be. Is there an issue with how I'm calculating the run time or is there a better way to calculate experience per hour? thanks the calculation code is in my onpaint() if that makes any difference. another thing after about 30 minutes it seems to just equal a 1:1 ratio where exp per hour is = to strength gained Edited August 29 by vladbuff Quote Link to comment Share on other sites More sharing options...
vladbuff Posted August 29 Author Share Posted August 29 (edited) I've realized the error is with how java divides ints normally in that it throws away the quotient and rounds. after changing my code to do the division without throwing away the quotient and it rounds the final number so the exp per hour doesn't have a decimal seems to be working for now. public void onStart() { startingStrengthEXP = getSkills().getExperience(Skill.STRENGTH); startTime = System.currentTimeMillis(); } int currentStrengthEXP = getSkills().getExperience(Skill.STRENGTH); final long runTime = System.currentTimeMillis() - startTime; double actualQuotient = (double)3600000 / runTime; Math.round(actualQuotient) * (currentStrengthEXP-startingStrengthEXP) Edited August 29 by vladbuff Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted August 29 Share Posted August 29 2 hours ago, vladbuff said: I've realized the error is with how java divides ints normally in that it throws away the quotient and rounds. after changing my code to do the division without throwing away the quotient and it rounds the final number so the exp per hour doesn't have a decimal seems to be working for now. public void onStart() { startingStrengthEXP = getSkills().getExperience(Skill.STRENGTH); startTime = System.currentTimeMillis(); } int currentStrengthEXP = getSkills().getExperience(Skill.STRENGTH); final long runTime = System.currentTimeMillis() - startTime; double actualQuotient = (double)3600000 / runTime; Math.round(actualQuotient) * (currentStrengthEXP-startingStrengthEXP) This is the method I have on my Timer class public int getPerHour(int value) { return (int) (value * 3600000d / (System.currentTimeMillis() - start)); } About the same as you have, except for the fact I multiply first instead of diving so there are no rounding errors 1 Quote Link to comment Share on other sites More sharing options...
vladbuff Posted August 29 Author Share Posted August 29 11 hours ago, Khaleesi said: This is the method I have on my Timer class public int getPerHour(int value) { return (int) (value * 3600000d / (System.currentTimeMillis() - start)); } About the same as you have, except for the fact I multiply first instead of diving so there are no rounding errors Really appreciate this as i was still getting rounding errors at 1hour+ with my new method currently testing yours right now ! Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted August 29 Share Posted August 29 5 hours ago, vladbuff said: Really appreciate this as i was still getting rounding errors at 1hour+ with my new method currently testing yours right now ! Ya that's why it's easier to multiple first and divide after Quote Link to comment Share on other sites More sharing options...