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.

How To Use Widgets

Featured Replies

I've seen a lot of people on here that still to this day think that using the basic run down getWidgets() method works.

Example: [DO NOT USE]

@Override
public int onLoop() {
  log(getWidgets().get(int rootId, int childId).getMessage());
  getWidgets().get(int rootId, int childId).interact();
  return 300;
}

Note: This is a big NO NO! The reason why is because you're not properly null checking the widgets, and will cause the script to fail if the widget returns as a null, so lets get started!

 

Basic Tutorial [FOR NOOBS]:

So lets take into consideration that you just want to do things with your widget but you find yourself down the road running into problems with it not working properly.

First we want to get our widget, but how do we do this? Simple let's call for a widget and store it!

private RS2Widget getMyWidget() {
  //Replace ids with your ids
  RS2Widget storedWidget = getWidgets().get(int rootId, int childId);
  return storedWidget;
}

 

Now that we have our basic method getMyWidget() created, we still need to null check getMyWidget() before using it. Below you will see how to use it in your onLoop() method!

@Override
public int onLoop() {
  if (getMyWidget() != null && getMyWidget().isVisible()) {
    log(getMyWidget().getMessage());
    getMyWidget().interact();
  } else {
    log("(Error) - Can't use any action for getMyWidget(). Returning as null or invisible.");
  }
  return 300;
}

You're now officially done, you've created a method to get your widget and to check if it's not null and is visible on screen!

BUT LETS KEEP GOING TO MAKE IT EVEN MORE SIMPLE!

 

Lets make a boolean method to check to see if our widget is working.

private boolean isMyWidgetWorking() {
  return getMyWidget() != null && getMyWidget().isVisible();
}

 

Now we have to change our original if statement in the onLoop() method.

@Override
public int onLoop() {
  if (isMyWidgetWorking()) {
    log(getMyWidget().getMessage());
    getMyWidget().interact();
  } else {
    log("(Error) - Can't use any action for getMyWidget(). Returning as null or invisible.");
  }
  return 300;
}

 

CONGRATULATIONS YOU'VE SUCCESSFULLY KNOW HOW TO USE A WIDGET! YOU'RE FINAL RESULTS SHOULD LOOK SIMILAR TO THE ONE BELOW:

private RS2Widget getMyWidget() {
  //Replace ids with your ids
  RS2Widget storedWidget = getWidgets().get(int rootId, int childId);
  return storedWidget;
}

private boolean isMyWidgetWorking() {
  return getMyWidget() != null && getMyWidget().isVisible();
}

@Override
public int onLoop() {
  if (isMyWidgetWorking()) {
    log(getMyWidget().getMessage());
    getMyWidget().interact();
  } else {
    log("(Error) - Can't use any action for getMyWidget(). Returning as null or invisible.");
  }
  return 300;
}

 

 

Advanced Tutorial [FOR PROS]:

This will be a more in depth guide that will teach you how to use widgets without ever having to use root and child ids. This makes it way more convenient for script writers that do not want to constantly update their widgets when Jagex updates the game.

 

We will continue off the Basic Tutorial, so for your getMyWidget() we are going to change a few things. But first I will teach you how to use the Widget Debugger that OSBot has in the Options.

First open up Settings in OSBot and select Options.

wsZ1kme.png

 

Now click on Debug and check the Widgets option.

VDEDNgo.png

 

Lets go into the game and check for a widget we can use.

j5TkqE0.png

 

So in this tutorial we will use the widget that has Look up name in it. We will have to query this widget in Widget Debugger so go back to OSBot Options and click on Widget Debugger.

sQkYGii.png

 

The widget we used was in the color of white, why use the white one and not the green one? Because it has the fields we need, that's all that matters. We will take these fields and add them to a filter to find the widget! So lets make a filter search in the method getMyWidget().

private RS2Widget getMyWidget() {
  List<RS2Widget> allWidgets = getWidgets().getAll();
  String[] actions = {"Look up name"};
  RS2Widget storedWidget = allWidgets.stream().filter(w -> w.getWidth() == 120 && w.getHeight() == 30 && w.getInteractActions() == actions).findFirst().orElse(null);
  return storedWidget;
}

 

Now we can change our onLoop() method and get rid of getMyWidget().getMessage() because it will return as null.

@Override
public int onLoop() {
  if (isMyWidgetWorking()) {
    getMyWidget().interact();
    log("(Info) - Succesfully clicked getMyWidget()!");
  } else {
    log("(Error) - Can't use any action for getMyWidget(). Returning as null or invisible.");
  }
  return 300;
}

 

THAT'S IT YOU ARE NOW OFFICIALLY A PRO AND WON'T HAVE TO EVER WORRY ABOUT UPDATING YOUR WIDGET! YOUR FINAL RESULTS SHOULD LOOK SIMILAR TO THE ONE BELOW:

private RS2Widget getMyWidget() {
  List<RS2Widget> allWidgets = getWidgets().getAll();
  String[] actions = {"Look up name"};
  RS2Widget storedWidget = allWidgets.stream().filter(w -> w.getWidth() == 120 && w.getHeight() == 30 && w.getInteractActions() == actions).findFirst().orElse(null);
  return storedWidget;
}

private boolean isMyWidgetWorking() {
  return getMyWidget() != null && getMyWidget().isVisible();
}

@Override
public int onLoop() {
  if (isMyWidgetWorking()) {
    getMyWidget().interact();
    log("(Info) - Successgully clicked getMyWidget()!")
  } else {
    log("(Error) - Can't use any action for getMyWidget(). Returning as null or invisible.");
  }
  return 300;
}

 

 

CREDITS:

  • Dream - Simplifying the methods above for an easy understanding!
  • OSBot Developers - For providing the API and being able to write your own scripts!
  • Me - For making a tutorial for noobs like you!

Edited by Ex0rcism
Updated guide for Advanced Tutorial.

So... in a lot of these methods, you're calling getWidget() multiple times back to back. This stresses the MethodProvider more than it has to as it retrieves an instance of this object every time you call it. You should only call the getWidget() method once in the entirety of the method you're using it in. For example,

private boolean isMyWidgetWorking() {
  RS2Widget wid = getMyWidget();
  return wid != null && wid.isVisible();
}

Also, having the above method just to check if the widget is working isn't really necessary. Just put it right in the if condition in onLoop().

Finally, I hear getWidget().singleFilter() works pretty nice 😉

  • Author
5 hours ago, camaro 09 said:

So... in a lot of these methods, you're calling getWidget() multiple times back to back. This stresses the MethodProvider more than it has to as it retrieves an instance of this object every time you call it. You should only call the getWidget() method once in the entirety of the method you're using it in. For example,


private boolean isMyWidgetWorking() {
  RS2Widget wid = getMyWidget();
  return wid != null && wid.isVisible();
}

Also, having the above method just to check if the widget is working isn't really necessary. Just put it right in the if condition in onLoop().

Finally, I hear getWidget().singleFilter() works pretty nice 😉

Yes, sorry was in rush making this tutorial will update and give credits.

And yes you can use singleFilter() but will cause warnings to your project unless you suppress it. Either way they both work perfectly fine I just think the List and getAllWidgets() is easier to understand on what is happening.

  • 1 month later...

Excellent explanation. The second tutorial will help me out a lot specifically lol.

  • 9 months later...

Hello,

I am completely lost, and maybe just dumb, but how do you find the widget ID you need?

I'm in a situation where I wanna cook Raw Shrimps, but I simply cannot figure out how to get the right widget, so I can supply the value...

Help is appreciated.

  • 1 month later...

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.