Jump to content

need help with script


Recommended Posts

Posted

hello trying to write my first script but i got a few problems

@Override
public int onLoop() throws InterruptedException {
    RS2Object stall = getObjects().closest("Tea Stall");
    Area area = Banks.VARROCK_EAST;
    if (getInventory().isFull()) {
        if (!area.contains(myPosition())) {
            getWalking().webWalk(area);
            getBank().open();
            if (bank.isOpen()) {
                bank.depositAll();
            } else {
                getBank().open();
            } else{
                getWalking().webWalk(area);
            } else{
                getWalking().webWalk(stall.getPosition());
            }
        }
    } else if (stall != null && !myPlayer().isAnimating()) {
        stall.interact("Steal-from");
    }
    return random(200, 300);
}

i already figured out that the problem is that i use : IF IF IF , ELSE ELSE ELSE  but need to use if else , else if .

But i cant figure out how i should do it exactly. Can someone please help me.

Posted (edited)
1 hour ago, nmba said:

hello trying to write my first script but i got a few problems



@Override
public int onLoop() throws InterruptedException {
    RS2Object stall = getObjects().closest("Tea Stall");
    Area area = Banks.VARROCK_EAST;
    if (getInventory().isFull()) {
        if (!area.contains(myPosition())) {
            getWalking().webWalk(area);
            getBank().open();
            if (bank.isOpen()) {
                bank.depositAll();
            } else {
                getBank().open();
            } else{
                getWalking().webWalk(area);
            } else{
                getWalking().webWalk(stall.getPosition());
            }
        }
    } else if (stall != null && !myPlayer().isAnimating()) {
        stall.interact("Steal-from");
    }
    return random(200, 300);
}

i already figured out that the problem is that i use : IF IF IF , ELSE ELSE ELSE  but need to use if else , else if .

But i cant figure out how i should do it exactly. Can someone please help me.

 

"the problem is that I use: IF IF IF, ELSE ELSE ELSE but need to use if else, else if."

At the risk of sounding rude, that's pretty nonsensical. I would highly recommend following some Java tutorials until you have a basic understanding of programming and logical constructs.

You'll find that it's much faster to learn that way rather than waiting for replies on here.

The best way to learn programming in my opinion, is to follow some tutorials, make things, Google when you get stuck, fix things yourself.

Perhaps try writing out some pseudocode, so you can get a clearer idea how this should be structured.

For example:

If my inventory is full:

    If I am not in the bank:

        Then walk to the bank

    Else if the bank is not open

        Then open the bank

   Else if.... Etc.

Else if I am not at the stalls:

    Then walk to the stalls

Etc.

Edited by Explv
  • Like 1
Posted

This is a matter of control flow statements. In java you use these statements to control how expressions are evaluated. Typically without the use of control flow statements your program will be read from top to bottom. In this case you want to evaluate if your inventory is full, whether or not the area (Varrock bank) contains your player, and if the bank is open.

You can use if statements to evaluate these but your implementation is convoluted. Try breaking it up in the 3 sections I described above. Test for these conditions. if they are met, what do you want your script to do and vis versa if they are not met what should happen. for example: if(getInventory.isFull) is not a necessary condition for the rest of your code. separate it: 

if (inventory.isFull() && !area.contains(myPlayer())) {
                getWalking().webWalk(area);
            }

or try a while loop that will evaluate all code inside its brackets so long as the condition is met. example: 

while(!area.contains(myPlayer())) {
            if (inventory.isFull()) {
                getWalking().webWalk(area);
				break;
            }
        }

this means that while your player is not in the defined area it will evaluate if the inventory is full. if it is full you will walk to the area. This code will constantly loop so long as your player is not in the area. 

Ultimately if you want to actually understand you need to teach yourself. Read the oracle guide on control flow statements: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/flow.html

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