mikehamz Posted October 14, 2018 Posted October 14, 2018 (edited) Method public boolean IsGainingXp (int CheckTime) { int XpChange; int CurrentXp = getSkills().getTotalExperience(); try { sleep(CheckTime); } catch (InterruptedException e) { e.printStackTrace(); } int LaterXp = getSkills().getTotalExperience(); XpChange = LaterXp-CurrentXp; if(XpChange>0) { return true; } else return false; } Example of use while (IsGainingXp(3000)==true) { log ("we have gained xp in the past 3 seconds"); } log ("we stopped gaining xp"); Sorry if this is useless but I couldn't use a check for animations so I made this to see if I gained XP recently. If someone has a better way please post. Edited October 14, 2018 by mikehamz
dreameo Posted October 14, 2018 Posted October 14, 2018 Hmm You might not want to block execution. You could create a global variable which keeps track of the current XP. Then you can make your check to see if your new XP is greater the the current. If it is, then just set your current XP to your new XP. Also: while(test() == true) // is equivalent to while(test()) 1
mikehamz Posted October 14, 2018 Author Posted October 14, 2018 56 minutes ago, dreameo said: Hmm You might not want to block execution. You could create a global variable which keeps track of the current XP. Then you can make your check to see if your new XP is greater the the current. If it is, then just set your current XP to your new XP. Also: while(test() == true) // is equivalent to while(test()) It is actually funny you post here because I saw your comment that I thought was really good that didn't block execution for checking idle time with animations, but it was after I had made this. Quote private boolean idleFor(int millis){ if(myPlayer().isAnimating()) { timeSinceAnimation = System.currentTimeMillis(); } else { timeSinceIdle = System.currentTimeMillis(); } return timeSinceAnimation + millis < timeSinceIdle; } Would editing your method to something like this work for checking Xp in stuff that doesn't do animations? private boolean NoXpFor(int millis){ if(getSkills().getTotalExperience() > globalXp) { TimeSinceXpGain = System.currentTimeMillis(); globalxp = getSkills().getTotalExperience(); } else { TimeSinceNoXp = System.currentTimeMillis(); } return TimeSinceXpGain + millis < TimeSinceNoXp; }