Jump to content

Amount input


Recommended Posts

Posted (edited)
RS2Widget w = getWidgets().get(162, 31);

if (w == null) {
  log("Widget not found");
  break;
}
if (w.isVisible()) {
  getKeyboard().typeString("5");
}

Works perfectly, thanks for the help guys

 

 

FYI, in this case. If the interface is null, it's also not visible.

if(w != null) getKeyboard().typeString("5"); else log("Widget not found");

will also work.

Edited by Zappster
Posted

FYI, in this case. If the interface is null, it's also not visible.

if(w != null) getKeyboard().typeString("5"); else log("Widget not found");

will also work.

Don't kill me when I'm wrong but with isVisible(); I'm assuming it's actually visible on the screen.

This means that the widget might not be null, but because of e.g. lag it's not visible instantly yet.

So checking if it's visible would be a good thing over only checking if it's not null.

  • Like 2
Posted

Don't kill me when I'm wrong but with isVisible(); I'm assuming it's actually visible on the screen.

This means that the widget might not be null, but because of e.g. lag it's not visible instantly yet.

So checking if it's visible would be a good thing over only checking if it's not null.

 

Fine example of "A programemr will look both ways before crossing a one way street" lol.

 

I've used this in my scripts and I don't get the problem. In some cases, you can have a wdiget that is there and not ready to show (such as in Zeah, the family stats are hidden but not null and still readable). However, in this case and with all cases of chat box interfaces, I believe the widget is created with the .isVisible set to true at all time and will never have a return of false. This is purely from my personal experience. I've not once had a moment in which the player typed in the chatbox before sending the message.

Posted (edited)
RS2Widget w = getWidgets().get(162, 31);

if (w == null) {
  log("Widget not found");
  break;
}
if (w.isVisible()) {
  getKeyboard().typeString("5");
}

Works perfectly, thanks for the help guys

 

you should really null check that widget before calling its isVisible(). incase you think you did. I have to tell you, you didn't.

 

The idea:

RS2Widget wid = getWidget(#,#);

if (wid == null) {
//the widget is null
} else {
//its not null
 if (wid.isVisible()) {
  //whatever........
 }
}

here the method I use

	public boolean canEnterAmount() {
		RS2Widget w = getWidgets().getWidgetContainingText(162, "Enter amount:");
		return w != null && w.isVisible();
	}
//this is what I normally do

if (!canEnterAmount()) {
//interact with something until it pops up
} else {
  getKeyboard().typeString("5", canEnterAmount());
}

that Boolean after the "5"  is there as a failsafe so incase you type in the chatbox. The message doesn't get sent out

Edited by Joseph

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