Jump to content

Running Loop Once then Nothing.


Recommended Posts

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

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
Posted

 

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?

Posted

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.

Posted

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
Posted

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.

Posted

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 

Posted

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

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

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