Jump to content

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


angelsdust

Recommended Posts

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

 

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...