Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • 2 NPEs


    Kristoffer

    Recommended Posts

    The NPEs occured in a subclass of my main class which extends AbstractScript.

     You should only have one class extends from AbstractScript, and that class must also have a ScriptManifest. If you want to have access to the methods available inside of the AbstractScript class outside of the class itself, then you can always pass a reference of the script as a argument to other class and/or method.

     

    For example:

    //The example class you need the AbstractScript methods.
    public class ExampleClass {
    
       private AbstractScript script;
    
       public ExampleClass (AbstractScript script) {
          this.script = script;
       }
    
       public int getHealth () {
          return script.getLocalPlayer().getHealth(); //We access the methods through the script variable
       }
    
    }
    

    Now if we need to initiate the class from inside our AbstractScript class we would do:

     ExampleClass example; //DO NOT INITIATE VARIABLE HERE!!! DO IT IN THE ONSTART()
    
    @Override
    public void onStart () {
       example = new ExampleClass(this); //Since we're inside of AbstractScript, we can pass the reference using the keyword "this"
       example.getHealth(); //Can use this method now
    }
    

    I hope this helps to clarify some things.

    Link to comment
    Share on other sites

    Yeah, I knew that. I just thought extending AbstractScript in a class and then extending that class to use the methods would also work. But as you described above is how I did it/have done it before.

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.