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.

calling methods between classes extending method provider

Featured Replies

I have just spent hours trying to figure out why I cannot call methods defined in one class which extends method provider in another class that extends method provider.

Is that just something which cannot be done?

 

I can use my methods from my classes which extend method provider in my main class because there I can use .exchangeContext(getBot()); but that only seems to exist for Script.

 

If I call a method from a class extending method provider in another class extending method provider it gives me a nullpointer error (even if it is just a setter or getter)... I could just work around this in my program design but if there is a way to call methods across classes extending method provider I would much rather do that for the sake of having a structured program.

  • Author
1 minute ago, Juggles said:

ClassName class = new Classname

class.getMethod

i know that :boge: .    I am doing that in my main class and it works there, but if I try to do it in a different class which also extends methodProvider it gives a nullPointerException

  • Author

In main method (works):

VariableActions varAction = new VariableActions(); //declared at top of class

varAction.exchangeContext(getBot()); //called in onStart()

varAction.AFK(); // called where  I want to use it

In other method that also extends methodContext (nullpointer):

VariableActions varAction = new VariableActions();
varAction.AFK();

 

Edited by Theorems

3 minutes ago, Theorems said:

i know that :boge: .    I am doing that in my main class and it works there, but if I try to do it in a different class which also extends methodProvider it gives a nullPointerException

Do you mean you can't compile it because it gives you errors or osbot is giving you NPE's

  • Author
2 minutes ago, Juggles said:

Do you mean you can't compile it because it gives you errors or osbot is giving you NPE's

It compiles fine, it's a runtime nullPointer error that only happens when I call a method in a class extending method provider from a class extending method provider.

44 minutes ago, Theorems said:

It compiles fine, it's a runtime nullPointer error that only happens when I call a method in a class extending method provider from a class extending method provider.

A - Main Class

B: Some Class Extends MethodProvidor 

C: Some Class Extends MethodProvider

 

If creating an instance of C in B, then you have to call exchangeContext and pass the bot reference. If you do this, you have to make sure that class B is instantiated in class A doing the same thing, exchangeContext. 

That way, there is a complete reference. A -> B -> C 

 

Think I understood what you're asking lol

Zzz, Think I know now what you mean

48 minutes ago, Theorems said:

VariableActions varAction = new VariableActions(); varAction.AFK();

When you do this, the original one in Main has no correlation to this one. It's a separate instance and therefore, it has not been initialized. 

Edited by dreameo

  • Author
17 minutes ago, dreameo said:

A - Main Class

B: Some Class Extends MethodProvidor 

C: Some Class Extends MethodProvider

 

If creating an instance of C in B, then you have to call exchangeContext and pass the bot reference. If you do this, you have to make sure that class B is instantiated in class A doing the same thing, exchangeContext. 

That way, there is a complete reference. A -> B -> C 

 

Think I understood what you're asking lol

Zzz, Think I know now what you mean

When you do this, the original one in Main has no correlation to this one. It's a separate instance and therefore, it has not been initialized. 

Yes you know what I mean, I should have done a better job explaining :) . So how would I then create that instance of 'B' in 'C' because unless I'm doing something wrong .exchangeContext() is only available if you are extending script.

Edit: nvm I think I see what you mean, ty for explaining.

Edited by Theorems

3 minutes ago, Theorems said:

Yes you know what I mean, I should have done a better job explaining :). So how would I then create that instance of 'B' in 'C' because unless I'm doing something wrong .exchangeContext() is only available if you are extending script.

 

exchangeContext is inherited from MethodProvider, so it would be available. 

  • Author
10 minutes ago, dreameo said:

exchangeContext is inherited from MethodProvider, so it would be available. 

That is strange, it just says "return type for the method is missing" when I go to use it in any class other than my Main.java

But I see it there in the api so I must just be doing something wrong...anyway I got it working now by moving some functionality to my main class and my updating variables to a class which doesn't have anything to do with method provider.

similar to what dreameo said but you can just call exchangeContext() in the constructor

X extends Script { //your main class

     private Y y;

     @Override

     public void onStart() {

         y = new Y(this);

     }

}

 

Y extends MethodProvider {

       Y(MethodProvider m) {

               exchangeContext(m.getBot());

       }

       @Override

       public int onLoop() {

             //do something

             return 0;

       }

}

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.