angelsdust Posted October 11, 2018 Share Posted October 11, 2018 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). Quote Link to comment Share on other sites More sharing options...
angelsdust Posted October 11, 2018 Author Share Posted October 11, 2018 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. Quote Link to comment Share on other sites More sharing options...
jca Posted October 11, 2018 Share Posted October 11, 2018 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() 1 Quote Link to comment Share on other sites More sharing options...
angelsdust Posted October 12, 2018 Author Share Posted October 12, 2018 9 hours ago, jca said: Yeah, pass the script instance and use exchangeContext() 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? Quote Link to comment Share on other sites More sharing options...
jca Posted October 12, 2018 Share Posted October 12, 2018 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. Quote Link to comment Share on other sites More sharing options...
zwaffel Posted October 12, 2018 Share Posted October 12, 2018 (edited) edit: nvm i'm actually not sure about wat i said, dont wane post wrong info. Edited October 12, 2018 by zwaffel Quote Link to comment Share on other sites More sharing options...