Jump to content

The currentStrenghtxp dont updates


Recommended Posts

Posted (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 by hajar424
Posted

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 

bHijlq7.png

 

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

  • Like 4
Posted

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();
    }
}
  • Like 1
Posted

 

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

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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