Jump to content
Sign in to follow this  
su1ts

Conditional sleeps while working with menues

Recommended Posts

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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

 

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...