Jump to content

need help with else if/if


atoo

Recommended Posts

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

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

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

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

 

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

 

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

 

 

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

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