Jump to content

Conditional sleeps while working with menues


Recommended Posts

Posted

Hello Guys,

i have some problems opening the POH menu. Sometimes this code works and sometimes it does not. I think the problem is when to sleep and maybe that the sleep times are to short. Can some1 help me please?

    public boolean callServant() {
        if(s.getTabs().getOpen() != Tab.INVENTORY) {
            s.getTabs().open(Tab.INVENTORY);
        }

        s.log("Open Settings Tab.");
        if(s.getTabs().open(Tab.SETTINGS)) {
            Sleep.sleepUntil(()-> s.getTabs().getOpen() == Tab.SETTINGS, 5000);
            s.log("Settings Tab opened.");

            Sleep.sleepUntil(()-> s.getWidgets().get(261, 71) != null && s.getWidgets().get(261,71).isVisible(), 10000);

                s.log("Try to open House options");
                if(s.getWidgets().get(261,71).interact()) {
                    s.log("Houuse options opened.");
                    Sleep.sleepUntil(()-> s.getWidgets().get(370,19) != null && s.getWidgets().get(370, 19).isVisible(), 10000);
                    s.log("Calling servant.");
                    if(s.getWidgets().get(370,19).interact()) {
                        s.log("Servant called!");
                        return true;
                    }
                }
            }
        return false;
    }

 

Posted (edited)

The issue is that you're trying to interact inside the if statement that opens the settings tab, so you're only going to be executing that code whenever you open the settings tab.

17 minutes ago, su1ts said:

Hello Guys,

i have some problems opening the POH menu. Sometimes this code works and sometimes it does not. I think the problem is when to sleep and maybe that the sleep times are to short. Can some1 help me please?


    public boolean callServant() {
        if(s.getTabs().getOpen() != Tab.INVENTORY) {
            s.getTabs().open(Tab.INVENTORY);
        }

        s.log("Open Settings Tab.");
      if (settings tab is open) {
        s.log("Try to open House options");
        if (house options are open) {
             if(s.getWidgets().get(370,19).interact()) {
                        s.log("Servant called!");
                        return true;
              } 
            } else {
              if(s.getWidgets().get(261,71).interact()) {
                    s.log("Houuse options opened.");
                    Sleep.sleepUntil(()-> s.getWidgets().get(370,19) != null && s.getWidgets().get(370, 19).isVisible(), 10000);
                    s.log("Calling servant."); 
                }
            }
      } else {
        if(s.getTabs().open(Tab.SETTINGS)) {
            Sleep.sleepUntil(()-> s.getTabs().getOpen() == Tab.SETTINGS, 5000);
            s.log("Settings Tab opened.");

            Sleep.sleepUntil(()-> s.getWidgets().get(261, 71) != null && s.getWidgets().get(261,71).isVisible(), 10000);              
            }
        return false;
    }

 

Instead you need to check if the settings tab is open, if not open it and so on. I've edited your code in the quote to demonstrate this.

Edited by d0zza
  • Like 1
Posted (edited)

 

As a note, this code works but I shouldn't be using the widget ids and instead be using the text to prevent the widgets breaking from update to update.

 

	private RS2Widget getServantWidget() {
		RS2Widget callWidget = widgets.get(370, 19);

		if (callWidget != null)
			callWidget = callWidget.getChildWidget(0);

		return callWidget;
	}

	private RS2Widget getHouseWidget() {
		RS2Widget houseWidget = widgets.get(261, 78);
		return houseWidget;
	}

	private boolean callServant() {
		if (tabs.open(Tab.SETTINGS)) {
			log("Settings tab open");

			RS2Widget widget = getServantWidget();

			if (widget != null) {
				if (widget.interact("Call Servant")) {
					if (!CTime.sleepUntil(random(1000, 2000), 100, () -> dialogues.inDialogue())) {
						return talkToButler();
					}
				}

			} else {
				widget = getHouseWidget();

				if (widget != null) {
					if (widget.interact("View House Options")) {
						CTime.sleepUntil(random(1250, 2000), 100, () -> getServantWidget() != null);
					}
				}
			}

		}

		return false;
	}

 

Edited by withoutidols

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