Jump to content

Amount input


lisabe96

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...