Jump to content

Using a package with Intelij can't access OSBot api?


Recommended Posts

Posted

Hello, not 100% scripting related but I am trying to clean up some of my code mess so I figured I should refactor it.

However when I try to place my custom classes into a package the classes in the package can no longer access the OSBot api and simple stuff like logging becomes impossible.

I am probably missing a config item somewhere but I can't find where, and using the search function I haven't found an answer either.

 

Starting to wonder weither or not this is possible in the first place, basically in my main script I import WackPackage.SickClassNameHere but the SickClassNameHere can't do anything.

Using Intelij 2018 CE with Linux. I configured my project like the tutorial here said (The 4 part one).

 

 

Posted
2 minutes ago, angelsdust said:

Right, spend all day messing around and looking at other code examples, you actually need to pass on the API (Script Class) and then you can use that. Because your own script extends the Script class it too extends the functions in it allowing you to use log etc.

 

I feel really stupid.

Yeah, pass the script instance and use exchangeContext()

  • Heart 1
Posted
2 hours ago, angelsdust said:

Oh, haven't seen any exchangeContext() being used in the scripts I copied it from. Thanks for the tip, according to the API documentation it's deprecated? What is it supposed to do?

Correction - exchangeContext actually takes a bot instance. 

So from your main class you pass getBot() to your custom class when you initialise it. You have your custom class extend MethodProvider then in the initialiser call exchangeContext(Bot). This gives you access to all the methods you need. 

Not sure why it’s deprecated. 

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