Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

need help with else if/if

Featured Replies

so basicly i think this is the problem with my script, im trying to add a YEW location to chop at aswell but when i add my yew thingies my script stops working. (no its not because of the update, my script works fine without the YEW added)

private State getState() {
        if (dialogues.isPendingContinuation())
            return State.LEVEL;
        else if (willowArea.contains(myPlayer()))
        	if(yewArea.contains(myPlayer())) < problem
            return State.CHOP;
        
        return State.IDLE;
    }

so the 2 areas, willow area and yew area are overlapping? with the yew area being inside of the willow area?

You have 3 if or else if statements that need there own return. And a default return for the methods. So you need 4 return types

Uh

 

If you're a little lost, i'd recommend putting curly brackets around each if statement, when you're learning it's an easy way to get confused if you leave them out.

(otherwise the if statement only applies to the next line)

 

Format it, look at it, and see if you can figure out what you've done wrong :) 

apa

private State getState() {
    if (dialogues.isPendingContinuation()) {
        return State.LEVEL;
    } else if (willowArea.contains(myPlayer()) || yewArea.contains(myPlayer())) { 
        return State.CHOP;
    }
    return State.IDLE;
}

??

  • Author

ok so i manange to fix the "freeze" on my script, but now it just jumps onto my anti ban and loops it.

I will try more and post results!


private State getState() {
    if (dialogues.isPendingContinuation()) {
        return State.LEVEL;
    } else if (willowArea.contains(myPlayer()) || yewArea.contains(myPlayer())) { 
        return State.CHOP;
    }
    return State.IDLE;
}

??

 

Still gets stuck on "loading script"

trying out various things atm


so the 2 areas, willow area and yew area are overlapping? with the yew area being inside of the willow area?

Not sure at the moment


 

Edited by atoo

  this : 

 else if (willowArea.contains(myPlayer()))
        	if(yewArea.contains(myPlayer())) 

is equivalent to this :

 else if (willowArea.contains(myPlayer()) && yewArea.contains(myPlayer())) 

There's some logic flaws in this code, I mean how can the player be in 2 differents area at the some moment??

 

try this :

else if (willowArea.contains(myPlayer()) || yewArea.contains(myPlayer())) 

Edited by MalikDz

  • Author

thatst what frosty posted, bot still freezes


the problem is definetly here

switch(getState()) {

            case LEVEL:
                dialogues.clickContinue();
                break;

            case CHOP:
                tree = objects.closest(willowArea, "Willow");
           
               tree = objects.closest(yewArea, "Yew"); //Broken?

Edited by atoo

 

thatst what frosty posted, bot still freezes

the problem is definetly here

switch(getState()) {

            case LEVEL:
                dialogues.clickContinue();
                break;

            case CHOP:
                tree = objects.closest(willowArea, "Willow");
           
               tree = objects.closest(yewArea, "Yew"); //Broken?

1.  Start by writing the right name of the tree you want to interact with , im sure the tree name is "Yew tree" and not "tree"

2. You are assigning a new value to the "tree" var and you're not even using it anywhere and then directly after you just reassign a new value to it ? flawed logic

3. Can you post more code , that snippet doesn't tell us much? 

Edited by MalikDz

 

With your object code:

  • You may get a NullPointerException if the tree is too far away, which will break your code and make you cry
  • If a tree is too far away, but not null, you may not be able to interact with it. You will need to walk up to it first.
if (yewTree != null && yewTree.exists() && getMap().distance(yewTree) <= 11) //valid yew tree
EDIT: shameless self plug here, using OmniAPI might shrink your code a little:
Entity yewTree = getEntityFinder().findClosest("Yew", (tree) -> (yewArea.contains(tree.getPosition()) && getMap().distance(tree) <= 11));
yewTree.interact("Chop-down"); //100% safe to do this, as OmniAPI returns empty objects instead of null
 
 

Edited by Bobrocket

  • Author

 

 

With your object code:

  • You may get a NullPointerException if the tree is too far away, which will break your code and make you cry
  • If a tree is too far away, but not null, you may not be able to interact with it. You will need to walk up to it first.
if (yewTree != null && yewTree.exists() && getMap().distance(yewTree) <= 11) //valid yew tree
EDIT: shameless self plug here, using OmniAPI might shrink your code a little:
Entity yewTree = getEntityFinder().findClosest("Yew", (tree) -> (yewArea.contains(tree.getPosition()) && getMap().distance(tree) <= 11));
yewTree.interact("Chop-down"); //100% safe to do this, as OmniAPI returns empty objects instead of null

 

Seems logical, I will do the same code for willow aswell.

Just need to get my laptop up first

  • Author

Okay i dont know if there was an RS update but my bot does not click anymore (when hoving over the trees)

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.