Jump to content
Sign in to follow this  
IceKontroI

Help with Conditions (EDIT: SOLVED)

Recommended Posts

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

  • Our picks

    • This release will:

      Fix key event handling issue


      Fix other event handling issue


      Fix RSServer hook


      Update world hopper to have it use OCR, thanks to Todd


      Use proper disposal of old Graphics objects


      Reformat code


      Rearrange code


      Organize code imports


      Apply around 8000 automated code refactorings


      Make preparations for Java 9


      Fix 11 various bugs


      Add more reliable debugging support


      Fix mouseEntered/Exited event dispatching bug


      Fix minimap walking bug where it opens the map


      Fix broken hooks for today's game update
        • Thanks
        • Like
      • 86 replies
    • This update will:

      Fix GE inventory item positioning bug


      Fix broken object hooks
        • Like
      • 27 replies
    • This release will:

      Fix some ClosedChannelException bug


      Fix bug in RSObject#getAllTiles


      Add game tab support for "Kourend Favour"
        • Like
      • 15 replies
    • This release will:

      Fix Settings UI placement bug


      Fix game object location bug


      Fix small layout bug making the client shift up and down


      Fix client crashing bug where loading the client with a small display area will cause the client to crash


      Fix annoying Linux bug relating to painting events and peers


      Fix settings saving bug where settings are saved to disk more often than they should


      Fix RSInterface#isBeingDrawn bug affecting a limited amount of people


      Drop Java 1.7 bytecode version for 1.8


      Important: Since the downloadable RS client uses Java 7, it will no longer be compatible with Looking Glass. To make up for this, we will add support for using other clients such as RuneLite (at a later date).


      This change was necessary to allow us to use Java 8 syntax. It also paves the way for Java 9/10/11 support.
        • Like
      • 40 replies
    • This update will:

      Fix the RSMenuNode bug which also fixes the bug with bank opening


      Fix the incorrect object positions bug


      Fix and re-enable the LG Objects API Accelerator


      Fix the RSObject#getAllTiles bug
        • Like
      • 22 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×