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.

Sleep until one of two widgets is visible?

Featured Replies

So I'm trying to use sleep until one of my widgets in query is visible, how would I do this?

 

Example of current code - 

 

        RS2Widget displaytaken = getWidgets().getWidgetContainingText(558, "Sorry, this display name is not available");
        RS2Widget displayabl = getWidgets().getWidgetContainingText(558, "Great! This display is available");

               keyboard.typeString(rsn);
               
               // I want to sleep after the above until " displayabl " or " displaytaken " is visible ( due to the delay of server response and also to make my script more efficient )
               // It would also be useful to know in this example for future reference, as straight the if statement below, there's another response that has a delay

                if(displaytaken != null && displaytaken.isVisible()) {

                    log("Display name is taken!");

                }
                else if(displayabl !=null && displaytaken.isVisible()) {

                    log("Setting display name!");
                    setname.hover();
                    mouse.click(false);

                }

 

I'm still pretty new to Botting and I know while/recursion loops are discouraged, but maybe this is an okay time to use one? I also haven't used widgets, but maybe this would work.

while(!displaytaken.isVisible() && !displayabl.isVisible()) {
sleep(10);
}

I don't know if I fully understand what you're asking, but I hope this helped.

Edited by jakealaka9

Best way to do this without freezing the whole script when it fails is this:

 

package mac;

public interface Condition {
	
	boolean evaluate();

}

 

	public boolean waitUntil(Condition c, int interval, int tries) throws InterruptedException {
		while (!c.evaluate()) {
			sleep(interval);
			if (tries == 0)
				return false;
			tries--;
		}
		return true;
	}

 

and then to use these

waitUntil(() -> widget.isVisible(), 200, 50);
if(!widget.isVisible()) return; //or whatever

//then here your amazing code

 

Which will try to see if the widget is visible every 200ms and try 50 times. 

 

Use a ConditionalSleep, it's exactly what they're for. 

The following snippet means "Sleep for 3 seconds, or until condition() returns true, where condition() is checked every 600ms"
 

new ConditionalSleep(3000, 600) {
    @Override
    public boolean condition() {
        RS2Widget widget = getWidgets().getWidgetContainingText(
                               558,
                               "Sorry, this display name is not available",
                               "Great! This display is available"
                           );
        return widget != null && widget.isVisible();
    }
}.sleep();


I already have a solution for the display name setter, if you would like to take a look. It just types some random String into the box, and then select one of the suggestions

https://github.com/Explv/Tutorial-Island/blob/master/src/sections/RuneScapeGuideSection.java#L82

Edited by Explv

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.