Jump to content

Running Loop Once then Nothing.


Expels

Recommended Posts

public int onLoop() throws InterruptedException {
		for (Node n : nodes) {
			if (n.validate()) {
				n.execute();
			}
		}
		return 200;
	}
	

When I run this, it checks validate and then executes, but after it has finished executing it just stands there?

 

 

 

how many nodes do you have, and can we see see your validate() statements? also are you sure its not continuously looping in your execute() methods?

  • Like 2
Link to comment
Share on other sites

how many nodes do you have, and can we see see your validate() statements? also are you sure its not continuously looping in your execute() methods?

 

Just one node.

	public boolean validate() throws InterruptedException {
		return tree != null && tree.hasAction("Chop down") && !sA.myPlayer().isAnimating() &&
				!sA.inventory.isFull();
Edited by Expels
Link to comment
Share on other sites

 

Just one node.

	public boolean validate() throws InterruptedException {
		return tree != null && tree.hasAction("Chop down") && !sA.myPlayer().isAnimating() &&
				!sA.inventory.isFull();

Why not just return one thing such as the inventory not being full and make it simpler instead of accessing a unnecessary tree variable you created when you don' t need it.

 

e.g for Chop

 

return !sA.getInventory().isFull();

 

for Drop

 

return sA.getInventory().isFull();

 

May or may not fix your problem but you don't need to null check something in your validate unless you were planning on doing something like this which I have in my BDK/Gwd 

 

(S.getGroundItems().closest(gi -> S.AREA_DRAGONS.contains(gi) && lootList.contains(gi.getName()) && S.getMap().canReach(gi)) != null);

 

Also im assuming your node framework was taken from Booch's tutorial right?

Link to comment
Share on other sites

Why not just return one thing such as the inventory not being full and make it simpler instead of accessing a unnecessary tree variable you created when you don' t need it.

 

e.g for Chop

 

return !sA.getInventory().isFull();

 

for Drop

 

return sA.getInventory().isFull();

 

May or may not fix your problem but you don't need to null check something in your validate unless you were planning on doing something like this which I have in my BDK/Gwd 

(S.getGroundItems().closest(gi -> S.AREA_DRAGONS.contains(gi) && lootList.contains(gi.getName()) && S.getMap().canReach(gi)) != null);

Also im assuming your node framework was taken from Booch's tutorial right?

 

If I just check if Inventory is full then it will just spam click. Doing it that way doesn't work anyway.

 

And yes.

Link to comment
Share on other sites

If I just check if Inventory is full then it will just spam click. Doing it that way doesn't work anyway.

 

And yes.

You do know validate only toggles the class to activate.

 

If it spams click that's you're interaction code :/

 

To fix 'spam clicks' use cond sleeps and checks i.e

 

long logCount =  getInventory().getAmount("Name of log"); 

 

and let's say ur interacting with a tree for eg

 

if(tree.interact("Chop down")) {

 

cond sleep(7500) 

 

return getInventory().getAmount("Name of log") > logCount;

 

that should fix spam clicks tbh

  • Like 1
Link to comment
Share on other sites

You do know validate only toggles the class to activate.

 

If it spams click that's you're interaction code :/

 

To fix 'spam clicks' use cond sleeps and checks i.e

 

long logCount =  getInventory().getAmount("Name of log"); 

 

and let's say ur interacting with a tree for eg

 

if(tree.interact("Chop down")) {

 

cond sleep(7500) 

 

return getInventory().getAmount("Name of log") > logCount;

 

that should fix spam clicks tbh

 

It would fix the spam clicking but it still doesn't loop it just stands there after chopping down the tree, there are no errors and the script doesn't stop, so I'm not really sure what is causing it.

Link to comment
Share on other sites

It would fix the spam clicking but it still doesn't loop it just stands there after chopping down the tree, there are no errors and the script doesn't stop, so I'm not really sure what is causing it.

Are you still using that tree variable at the top of your class?

 

Could you share more code? It'd really help 

 

Your full chop class and ur main class preferably 

Link to comment
Share on other sites

Are you still using that tree variable at the top of your class?

 

Could you share more code? It'd really help 

 

Your full chop class and ur main class preferably 

private List<Node> nodes = new ArrayList<Node>();

	@[member=Override]
	public void onStart() {
		Collections.addAll(nodes, 
				new Chopping(this));
	}
	
	
	@[member=Override]
	public int onLoop() throws InterruptedException {
		for (Node n : nodes) {
			if (n.validate()) {
				n.execute();
				break;
			}
		}
		return 200;
	}
Constants c = new Constants();
	RS2Object tree = sA.objects.closest("Tree");
	
	public Chopping(Script sA) {
		super(sA);
		// TODO Auto-generated constructor stub
	}

	@[member=Override]
	public boolean validate() throws InterruptedException {
		return !sA.inventory.isFull();
		
	}

	@[member=Override]
	public int execute() {
		if (tree != null) {
			tree.interact("Chop down");
			new ConditionalSleep(1000, 4000) {
				
				@[member=Override]
				public boolean condition() throws InterruptedException {
					// TODO Auto-generated method stub
					return !sA.myPlayer().isAnimating();
				}
			}.sleep();
		} else {
			sA.camera.toEntity(tree);
		}
		return 200;
	}

}
Link to comment
Share on other sites

private List<Node> nodes = new ArrayList<Node>();

	@[member='Override']
	public void onStart() {
		Collections.addAll(nodes, 
				new Chopping(this));
	}
	
	
	@[member='Override']
	public int onLoop() throws InterruptedException {
		for (Node n : nodes) {
			if (n.validate()) {
				n.execute();
				break;
			}
		}
		return 200;
	}
Constants c = new Constants();
	RS2Object tree = sA.objects.closest("Tree");
	
	public Chopping(Script sA) {
		super(sA);
		// TODO Auto-generated constructor stub
	}

	@[member='Override']
	public boolean validate() throws InterruptedException {
		return !sA.inventory.isFull();
		
	}

	@[member='Override']
	public int execute() {
tree = sA.objects.closest("Tree");
		if (tree != null) {
			tree.interact("Chop down");
			new ConditionalSleep(1000, 4000) {
				
				@[member='Override']
				public boolean condition() throws InterruptedException {
					// TODO Auto-generated method stub
					return !sA.myPlayer().isAnimating();
				}
			}.sleep();
		} else {
			sA.camera.toEntity(tree);
		}
		return 200;
	}

}

 

you only call "tree = sA.objects.closest("Tree");" once when you make an instance of the class.

id recommend adding it into the execute method as the first line as above. also, id make it a local variable instead of global.

  • Like 3
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...