Jump to content

What do i do wrong?


Sebastian

Recommended Posts

Hi Osbot scripters!

 

I have been f*cking around with this all morning. I have no idea what i'm doing wrong. removing the } else { wont work either.. Oaks and Willows are working. Yews are not..

 

EDIT: Tried Else if statements. Didn't work either. 

		case CHOP:
			Entity Yew = objects.closest("Yew");
			Entity Willow = objects.closest("Willow");
			Entity Oak = objects.closest("Oak");
			if (Willow != null) {
				if (Willow.isVisible()) {
					Willow.interact("Chop down");
				} else {
					sleep(random(500, 700));
				}
			} else if (Oak != null) {
				if (Oak.isVisible()) {
					Oak.interact("Chop down");
				} else {
					sleep(random(500, 700));
				}
			} else if (Yew != null) {
				if (Yew.isVisible()) {
					Yew.interact("Chop down");
				} else {
					sleep(random(500, 700));
				}
			}
		case CHOP:
			Entity Willow = objects.closest("Willow");
			if (Willow != null) {
				if (Willow.isVisible()) {
					Willow.interact("Chop down");
				} else {
					sleep(random(500, 700));
				} 
				} else {
				Entity Oak = objects.closest("Oak");
				if (Oak != null) {
					if (Oak.isVisible()) {
						Oak.interact("Chop down");
					} else {
						sleep(random(500, 700));
					}
				} else {
					Entity Yew = objects.closest("Yew");
					if (Yew != null) {
						if (Yew.isVisible()) {
							Yew.interact("Chop down");
						} else {
							sleep(random(500, 700));
						}
					}
				}
			}
Edited by OSRS Sebastian
Link to comment
Share on other sites

Have you tried adding logs 
 

log("Can I reach this statement?");

and also what does your getState look like?

 

 

You should also look into the InteractionEvent API. it handles visibility checks etc. Real easy to use

 

http://osbot.org/api/org/osbot/rs07/event/InteractionEvent.html

 

EXAMPLE SNIPPET:

public boolean interact(final Entity entity, final String option) {
InteractionEvent IE = new InteractionEvent(entity, option);
 IE.setOperateCamera(false);
 IE.setWalkTo(false);
 IE.setHover(true);
    if(IE != null) {
	execute(IE);
         //other checks 
    }
}

//
if (interact(tree,"Chop")) 
///

Edited by Trinity
Link to comment
Share on other sites

Have you tried adding logs 

 

log("Can I reach this statement?");

and also what does your getState look like?

 

 

You should also look into the InteractionEvent API. it handles visibility checks etc. Real easy to use

 

I will look into interactionEvent. But i find it very difficult to understand the api somehow.. 

	private State getState() {
		Entity treeE = objects.closest(tree);
		if (inventory.isFull())
			return State.BANK;
		if (treeE != null && treeE.isVisible())
			if (!myPlayer().isAnimating())
				return State.CHOP;
		return State.WAIT;
	}

	private enum State {
		CHOP, WAIT, BANK, // DROP
	};

Link to comment
Share on other sites

 

I will look into interactionEvent. But i find it very difficult to understand the api somehow.. 

	private State getState() {
		Entity treeE = objects.closest(tree);
		if (inventory.isFull())
			return State.BANK;
		if (treeE != null && treeE.isVisible())
			if (!myPlayer().isAnimating())
				return State.CHOP;
		return State.WAIT;
	}

	private enum State {
		CHOP, WAIT, BANK, // DROP
	};

 

Looks okay to me. You said it works for 2 trees? Can you throw in some log statements inside the case and run it for me?

  • Like 1
Link to comment
Share on other sites

Yes or just in the Chop case between each tree

 

Have set a log for every tree type. Willow and Oak logs perfectly. But the Yew log doesn't show up.. so i'm guessing it doesn't read that peace of code..

[INFO][Bot #1][11/30 02:09:51 PM]: Started script : SBWoodcutter
[INFO][Bot #1][11/30 02:09:52 PM]: Chopping Oak tree
[INFO][Bot #1][11/30 02:09:56 PM]: Script SBWoodcutter has paused!
[INFO][Bot #1][11/30 02:09:58 PM]: Script SBWoodcutter has resumed!
[INFO][Bot #1][11/30 02:09:58 PM]: Chopping Oak tree
		case CHOP:
			Entity Yew = objects.closest("Yew");
			Entity Willow = objects.closest("Willow");
			Entity Oak = objects.closest("Oak");
			if (Willow != null) {
				if (Willow.isVisible()) {
					Willow.interact("Chop down");
					log("Chopping Willow tree");
				} else {
					sleep(random(500, 700));
				}
			} else if (Oak != null) {
				if (Oak.isVisible()) {
					Oak.interact("Chop down");
					log("Chopping Oak tree");
				} else {
					sleep(random(500, 700));
				}
			} else if (Yew != null) {
				if (Yew.isVisible()) {
					Yew.interact("Chop down");
					log("Chopping Yew tree");
				} else {
					sleep(random(500, 700));
				}
			}
			break;
Link to comment
Share on other sites

 

Have set a log for every tree type. Willow and Oak logs perfectly. But the Yew log doesn't show up.. so i'm guessing it doesn't read that peace of code..

[INFO][Bot #1][11/30 02:09:51 PM]: Started script : SBWoodcutter
[INFO][Bot #1][11/30 02:09:52 PM]: Chopping Oak tree
[INFO][Bot #1][11/30 02:09:56 PM]: Script SBWoodcutter has paused!
[INFO][Bot #1][11/30 02:09:58 PM]: Script SBWoodcutter has resumed!
[INFO][Bot #1][11/30 02:09:58 PM]: Chopping Oak tree
		case CHOP:
			Entity Yew = objects.closest("Yew");
			Entity Willow = objects.closest("Willow");
			Entity Oak = objects.closest("Oak");
			if (Willow != null) {
				if (Willow.isVisible()) {
					Willow.interact("Chop down");
					log("Chopping Willow tree");
				} else {
					sleep(random(500, 700));
				}
			} else if (Oak != null) {
				if (Oak.isVisible()) {
					Oak.interact("Chop down");
					log("Chopping Oak tree");
				} else {
					sleep(random(500, 700));
				}
			} else if (Yew != null) {
				if (Yew.isVisible()) {
					Yew.interact("Chop down");
					log("Chopping Yew tree");
				} else {
					sleep(random(500, 700));
				}
			}
			break;

add my skype: osbotsinatra1

Link to comment
Share on other sites

 

Hi Osbot scripters!

 

I have been f*cking around with this all morning. I have no idea what i'm doing wrong. removing the } else { wont work either.. Oaks and Willows are working. Yews are not..

 

EDIT: Tried Else if statements. Didn't work either. 

		case CHOP:
			Entity Yew = objects.closest("Yew");
			Entity Willow = objects.closest("Willow");
			Entity Oak = objects.closest("Oak");
			if (Willow != null) {
				if (Willow.isVisible()) {
					Willow.interact("Chop down");
				} else {
					sleep(random(500, 700));
				}
			} else if (Oak != null) {
				if (Oak.isVisible()) {
					Oak.interact("Chop down");
				} else {
					sleep(random(500, 700));
				}
			} else if (Yew != null) {
				if (Yew.isVisible()) {
					Yew.interact("Chop down");
				} else {
					sleep(random(500, 700));
				}
			}
		case CHOP:
			Entity Willow = objects.closest("Willow");
			if (Willow != null) {
				if (Willow.isVisible()) {
					Willow.interact("Chop down");
				} else {
					sleep(random(500, 700));
				} 
				} else {
				Entity Oak = objects.closest("Oak");
				if (Oak != null) {
					if (Oak.isVisible()) {
						Oak.interact("Chop down");
					} else {
						sleep(random(500, 700));
					}
				} else {
					Entity Yew = objects.closest("Yew");
					if (Yew != null) {
						if (Yew.isVisible()) {
							Yew.interact("Chop down");
						} else {
							sleep(random(500, 700));
						}
					}
				}
			}

 

Probably just that there isn't a Yew tree nearby??

 

Also if you are near a Yew tree, and there is an Oak or Willow nearby it will try and cut those first.

 

I suggest you change your yew code to:

else {

    Entity Yew = getObjects().closest("Yew");
    if (Yew != null) {

        if (Yew.isVisible()) {

            log("Chopping Yew");
            Yew.interact("Chop down");
        } else {

            log("Yew is not visible");
            sleep(random(500, 700));
        }
    } else{
    
        log("Yew is null");
    }
}

And view the logger so you can see what's happening.

 

On a side note your code can be simplified to:

case CHOP:
    
    Entity yew = getObjects().closest("Yew"), 
    willow = getObjects().closest("Willow"),
    oak = getObjects().closest("Oak");

    if (willow != null && willow.isVisible()) willow.interact("Chop down");
    else if (oak != null && oak.isVisible()) oak.interact("Chop down");
    else if (yew != null && yew.isVisible()) yew.interact("Chop down");
    else sleep(random(500, 700));

Side note 2: variable names should always be lowercase

 

 

I would also suggest you take a look at Java Swing, there are some tutorials here on OSBot, and create a GUI that lets the user select which kind of tree they want to chop.

 

Edited by Explv
  • Like 1
Link to comment
Share on other sites

Probably just that there isn't a Yew tree nearby??

Also if you are near a Yew tree, and there is an Oak or Willow nearby it will try and cut those first.

I suggest you change your yew code to:

else {    Entity Yew = getObjects().closest("Yew");    if (Yew != null) {        if (Yew.isVisible()) {            log("Chopping Yew");            Yew.interact("Chop down");        } else {            log("Yew is not visible");            sleep(random(500, 700));        }    } else{            log("Yew is null");    }}
And view the logger so you can see what's happening.

On a side note your code can be simplified to:

case CHOP:        Entity yew = getObjects().closest("Yew"),     willow = getObjects().closest("Willow"),    oak = getObjects().closest("Oak");    if (willow != null && willow.isVisible()) willow.interact("Chop down");    else if (oak != null && oak.isVisible()) oak.interact("Chop down");    else if (yew != null && yew.isVisible()) yew.interact("Chop down");    else sleep(random(500, 700));
Side note 2: variable names should always be lowercase

I would also suggest you take a look at Java Swing, there are some tutorials here on OSBot, and create a GUI that lets the user select which kind of tree they want to chop.

Hey! Thanks for the reply. I will try this after dinner. Thing is, i have a GUI. Works on willows and oaks. But the yew he cant find. Even tho i'm standing next to it. Maybe insert the id of the yew instead of the name?

And for the lower case vars. Thanks, really apriciate it!

Link to comment
Share on other sites

Hey! Thanks for the reply. I will try this after dinner. Thing is, i have a GUI. Works on willows and oaks. But the yew he cant find. Even tho i'm standing next to it. Maybe insert the id of the yew instead of the name?

And for the lower case vars. Thanks, really apriciate it!

 

Feel free to PM me and I can take a look at the full source code for you

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