Jump to content

having issues calculating EXP per hour


vladbuff

Recommended Posts

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 by vladbuff
Link to comment
Share on other sites

Posted (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 by vladbuff
Link to comment
Share on other sites

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 :)

  • Like 1
Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...