Jump to content

need help with script


nmba

Recommended Posts

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.

Link to comment
Share on other sites

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

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

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