Jump to content

The currentStrenghtxp dont updates


hajar424

Recommended Posts

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

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

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

 

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
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...