hajar424 Posted July 11, 2015 Posted July 11, 2015 (edited) My Current strenght xp dont changes when i attack someone, and when i try to put the variables in the onloop() i get error because onPaint() metod cant use variables from onLoop() @Override public void onPaint(Graphics2D g) { int currentStrenghtxp = skills.getExperience(Skill.STRENGTH); int beginningStrenghtxp = (skills.getExperience(Skill.STRENGTH)); int strenghtXpGained = currentStrenghtxp - beginningStrenghtxp; g.setColor(new Color(25, 25, 25, 100)); g.fillRect(7, 345, 516, 320); g.setColor(new Color(228, 211, 22)); g.drawString("Current:"+strenghtXpGained,10,364); } Edited July 11, 2015 by hajar424
Wiz Khalifa Posted July 11, 2015 Posted July 11, 2015 put the beginningStrengthxp at your onStart methode.
hajar424 Posted July 11, 2015 Author Posted July 11, 2015 put the beginningStrengthxp at your onStart methode. I get a error then saying that it dont know the variable
Flamezzz Posted July 11, 2015 Posted July 11, 2015 You could use http://osbot.org/api/org/osbot/rs07/api/util/ExperienceTracker.html Put experienceTracker.startAll(); in onStart()
Apaec Posted July 11, 2015 Posted July 11, 2015 loll So the problem you have here is that you're defining start and current exps in the same place so obv they will both be the same so when you subtract 1 from the other you will get 0. Define startStrExp as a global variable and give it a value in onstart. Keep the current value where it is. Then it will work haha -apa I get a error then saying that it dont know the variable there are 2 types of variable, global and local. Local is where you define a variable INSIDE a method eg public void hello() { int i = 10; log("value of i: " + i); } A global variable is something you define globally i.e it can be reached from any method inside your class eg private int n = 1337; public int getn() { return n; } apa for more info google 'local vs global variables java' or something like taht 4
hajar424 Posted July 11, 2015 Author Posted July 11, 2015 You could use http://osbot.org/api/org/osbot/rs07/api/util/ExperienceTracker.html Put experienceTracker.startAll(); in onStart() -SOLVED- Thanks Flamezzz g.drawString("Current:"+ experienceTracker.getGainedXP(Skill.STRENGTH),10,364);
Bobrocket Posted July 11, 2015 Posted July 11, 2015 With all due respect, you should really look up the basics of Java. Your problem exists because you are defining "beginningStrengthExp" in the function scope. The hierarchy for variable scopes goes class > function. If you want your variables to be used in many functions, you put them in the class scope. public class Main extends Script { private int beginningStrengthExp; public void onStart() { beginningStrengthExp = <code>; } public void onPaint(Graphics2d g) { int x = beginningStrengthExp; } } In this example, we can access beginningStrengthExp because it was defined in the class. We cannot, however, access beginningStrengthExp with an instance of Main because it is set to private. To solve this, we add a getter value: public int getBeginningStrengthExp() { return beginningStrengthExp; } So this can be used when we need to grab it from an instance of Main: public class SomeArbitraryClass { public SomeArbitraryClass(Main m) { int beginningStrengthExp = m.getBeginningStrengthExp(); } } 1
Khaleesi Posted July 11, 2015 Posted July 11, 2015 My Current strenght xp dont changes when i attack someone, and when i try to put the variables in the onloop() i get error because onPaint() metod cant use variables from onLoop() @Override public void onPaint(Graphics2D g) { int currentStrenghtxp = skills.getExperience(Skill.STRENGTH); int beginningStrenghtxp = (skills.getExperience(Skill.STRENGTH)); int strenghtXpGained = currentStrenghtxp - beginningStrenghtxp; g.setColor(new Color(25, 25, 25, 100)); g.fillRect(7, 345, 516, 320); g.setColor(new Color(228, 211, 22)); g.drawString("Current:"+strenghtXpGained,10,364); } bcs u set begin exp every single second to the current value ... only call it onStart 1