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.

Issues with 'throws InterruptedException'

Featured Replies

Hi guys!

I am trying to use multiple classes to ease my debugging and readability.

When I make a new class and use throws 'InterruptedException' after the function declaration this allows me to use functions such as: 

sleep(random(670,944));

in my main I do the following:

private GielenorGuide doGilGuide = new GielenorGuide();
doGilGuide.exchangeContext(getBot());

However, this means when I exchange context in the onStart function and call doGilGuide.Functionname(); The script will not start.

Removing the throws InterruptedException from all function declerations will allow my script to work but at the cost of having to use conditional sleeps for literally everything which is a very verbose solution for things where you just want a simple sleep.

Is there any way I can make it so I can just use sleeps while still being able to exchange context within my main.

yes dont use deprecated .exchangeContext()

  • Author
4 hours ago, Chris said:

yes dont use deprecated .exchangeContext()

What is the alternative? I am kind of new to OO programming coming from Python & C/C++. I have figured everything else out so far but this seems to be the last kind of hurdle for now.

58 minutes ago, Zappster said:

Maybe read an intro on try + catch statments

https://www.w3schools.com/java/java_try_catch.asp

I only wanted to implement basic 1x line sleeps instead of conditional sleeps everywhere for basic code. Try catching everything wouldn't achieve this.

  • Author
2 minutes ago, Malcolm said:

Arguably you're supposed to exchange context but either or really works. I don't see an issue with doing either way.

image.thumb.png.438b8304bd9f0fbb426b0296210d75ad.png

 

If you exchange context you are supposed to extend MethodProvider in your other class and then you can call the methods within that class in your main class

For example if you exchange context you'd do something like this


 


ClassName cls = new ClassName();

public void onStart() {

cls.exchangeContext().getbot());

}

public int onLoop() {

cls.method();

return 150;

}

 

and in your other class you'd just do this


public class ClassName extends MethodProvider {

 

The alternative is to do something like this without extending MethodProvider and without exchanging context.
 


public void method(ClassName cls) {

cls.callMethod();

}

 

 

 

I do exchange context as show and extend method provider but the issue persists.

Idk why so many OSBot people create new instances of MethodProvider. Why don't you just use dependency injection, inject your already existing MethodProvider, then call directly from that..? 

 

For instance:

class Bla {

private MethodProvider methodProvider;

public Bla(MethodProvider methodProvider) {

this.methodProvider = methodProvider;

}

 

public void bla2() {

methodProvider.callSomeUselessFunction();

}

}

 

Then to create that object instance, new Bla(methodProviderInstance);

 

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.