Jump to content

need help with else if/if


Recommended Posts

Posted

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;
    }
Posted

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

  • Like 1
Posted (edited)

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
Posted (edited)

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

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
Posted (edited)

 

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

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
  • Like 2
Posted

 

 

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

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