Jump to content

Extending method provider and nullpointerexception


Recommended Posts

Posted
13 hours ago, progamerz said:

There is no other way lol

You have access to the bot context.

 

14 hours ago, dreameo said:

When you're extending MethodProvider, some inherited fields must be initialized. That is the only reason why you're getting null. 

What those fields are, i'm not sure (take a look in Script class and see how it handles it). There are different ways on dealing this situation. @Alek Can tell you the preferred way. I think he mentioned it before in the forums. 

By design scripters shouldn't use anything that's marked for internal use only. They should pass bot which derives everything for that instance. I don't even extend MethodProvider in our API, it just doesn't make sense from a design perspective - we pass MethodProvider or Bot. I'd encourage other scripters to do the same, but it's your code so do whatever you guys like! :)  
 

  • Like 2
Posted (edited)
45 minutes ago, Alek said:

By design scripters shouldn't use anything that's marked for internal use only. They should pass bot which derives everything for that instance. I don't even extend MethodProvider in our API, it just doesn't make sense from a design perspective - we pass MethodProvider or Bot. I'd encourage other scripters to do the same, but it's your code so do whatever you guys like! :)  
 

 

Aye, passing MethodProvider or Bot as a parameter is certainly "better", I just hate having every API call prefixed with some variable like methods.myPlayer() or whatever, and every class having MethodProvider as a constructor parameter. It just makes me feel a little sad when I look at it :feels:

If I was writing a small script for sure I would just pass the context as a parameter, but for large scripts it starts getting ugly.

I guess an alternative would be to have a static MethodProvider variable in your main class, and access the API via that, but again... *shudder* not gucci

Edited by Explv
  • Like 1
  • Boge 1

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