Welcome to TRiBot Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0
IceKontroI

Help with Conditions (EDIT: SOLVED)

4 posts in this topic

EDIT: Figured it out. Needed to do

while (!stop.active()) {

    // continue walk process

}

Feel free to use this post as a reference if you are having the same problem.

I would like to add a stopping condition to a custom walking method I wrote, but I can't seem to get the condition to recalculate each time; it just keeps using the original value I fed into it on method start. Here's some pseudo code to give you an idea what I'm working with:

public static void walkMethod(RSTile[] path, Condition stop) {
	System.out.println("Beginning walk process.");
	while (stop != null && pathList.size() > 0) {
		// select tile to walk to
		// click tile
		// sleep
	}
}

And the Condition looks like:

	static Rectangle destinationArea = new Rectangle(1, 1, 4, 6);

	static Condition stoppingCondition =  new Condition() {
		public boolean active() {
			System.out.println("THIS TEXT SHOULD BE VISIBLE.");
			General.sleep(10);
			RSTile playerTile = Player.getPosition();
			Point playerPoint = new Point(playerTile.getX(), playerTile.getY());
			return destinationArea.contains(playerPoint);
		}
	};

The first thing I don't understand is what Conditions actually return. I would assume it's either true or false, but it seems to be more than that. This will help me figure out how to word my while loop so it can stop when the player's position is in the destinationArea.

The other thing I don't get is how to make the Condition run through each line whenever it's called within the containing walkMethod(). I should be seeing the "THIS TEXT SHOULD BE VISIBLE." text every time the while loop in walkMethod() iterates but it never displays.

Any insight into how I'm doing this wrong would be greatly appreciated. I wish I didn't have to ask on the forums, but there isn't any good documentation anywhere on how Conditions work (on tribot Conditions at least).

Edited by IceKontroI

Share this post


Link to post
Share on other sites

@IceKontroI

Conditions should return true if the walking method should break early, and false if it shouldn't.
 

It is encouraged to use the premade Walking methods, you can add the condition as a argument in most functions, and it will be checked constantly while walking.
Walking#walkPath would fit your case.

The stopping_condition_delay argument is the amount of 'sleep' that is used while constantly checking your condition during walking.

 

Please don't be afraid to ask :) I think many of us would be glad to help you.

Share this post


Link to post
Share on other sites

@laniax thank you, but as it turns out I figured out the problem almost immediately after posting. Turns out you can't check if the Condition == a boolean value, but you can check if the Condition.active() == a boolean value, which solved the problem.

Share this post


Link to post
Share on other sites
3 minutes ago, IceKontroI said:

@laniax thank you, but as it turns out I figured out the problem almost immediately after posting. Turns out you can't check if the Condition == a boolean value, but you can check if the Condition.active() == a boolean value, which solved the problem.

That is correct, but it is still recommended to use the Walking methods, since it will check your condition async instead of, for example, only before clicking.
It has extra antiban as well.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.