Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Troubles with ConditionalSleep

Featured Replies

Been trying to use a ConditionalSleep to check when the trade window opens up, but it seems to just timeout before it even realises that it's actually trading.

 

log("before cond");
log(trade.isCurrentlyTrading()); // returns false, as expected
condSleep(10000, 200, trade.isCurrentlyTrading());
log("after cond");
log(trade.isCurrentlyTrading()); // returns true, as expected

// also in the class
	private void condSleep(int timeout, int delay, boolean b) {
		new ConditionalSleep(timeout, delay) {
			@Override
			public boolean condition() throws InterruptedException {
				return b;
			}
		}.sleep();
	}

 

Any help would be greatly appreciated!

You're passing the boolean as false condSleep(10000, 200, trade.isCurrentlyTrading()); 

This means it will sleep for 10 seconds every time. You need to pass a boolean supplier like so:

log("before cond");
log(trade.isCurrentlyTrading()); // returns false, as expected
condSleep(10000, 200, () -> trade.isCurrentlyTrading());
log("after cond");
log(trade.isCurrentlyTrading()); // returns true, as expected

// also in the class
	private void condSleep(int timeout, int delay, BooleanSupplier b) {
		new ConditionalSleep(timeout, delay) {
			@Override
			public boolean condition() throws InterruptedException {
				return b.asBoolean();
			}
		}.sleep();
	}

 

  • Author
1 minute ago, nosepicker said:

You're passing the boolean as false condSleep(10000, 200, trade.isCurrentlyTrading()); 

This means it will sleep for 10 seconds every time. You need to pass a boolean supplier like so:


log("before cond");
log(trade.isCurrentlyTrading()); // returns false, as expected
condSleep(10000, 200, () -> trade.isCurrentlyTrading());
log("after cond");
log(trade.isCurrentlyTrading()); // returns true, as expected

// also in the class
	private void condSleep(int timeout, int delay, BooleanSupplier b) {
		new ConditionalSleep(timeout, delay) {
			@Override
			public boolean condition() throws InterruptedException {
				return b.asBoolean();
			}
		}.sleep();
	}

 

I'm not entirely sure what you're talking about tbh, but the method I use works fine for things such as bank.isOpen(), so I'm still at a loss of why it works for some booleans and not others?

18 minutes ago, Slut said:

I'm not entirely sure what you're talking about tbh, but the method I use works fine for things such as bank.isOpen(), so I'm still at a loss of why it works for some booleans and not others?

new ConditionalSleep(timeout, delay) {
			@Override
			public boolean condition() throws InterruptedException {
				return b.asBoolean();
			}
		}.sleep();

This little thing here. It says sleep for a maximum time of TIMEOUT and check every DELAY time if the CONDITION is true.

Now when you pass 10000, 200, false as parameters it means that, hey sleep for 10 seconds and check every 200ms if true == false, which will never be true, so it will sleep for 10 seconds. The boolean you pass is a "constant" let's say.

Bolean supplier "fetches" the true/false result from the CONDITION whenever it's invoked. So it will check if it's true/false every 200ms in your case.

Edited by nosepicker

  • Author
4 minutes ago, nosepicker said:

new ConditionalSleep(timeout, delay) {
			@Override
			public boolean condition() throws InterruptedException {
				return b.asBoolean();
			}
		}.sleep();

This little thing here. It says sleep for a maximum time of TIMEOUT and check every DELAY time if the CONDITION is true.

Now when you pass 10000, 200, false as parameters it means that, hey sleep for 10 seconds and check every 200ms if true == false, which will never be true, so it will sleep for 10 seconds. The boolean you pass is a "constant" let's say.

Bolean supplier "fetches" the true/false result from the CONDITION whenever it's invoked. So it will check if it's true/false every 200ms in your case.

Ah I see! Thanks for your thorough explanation, really helped :)

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.