Jump to content

Scripting with classes


Recommended Posts

Posted (edited)

I am new to scripting and so far when I created a script, I put it all in one class and things went pretty smoothly. But now I wanted to learn how to script while also using different classes and Ive tried stuff but nothing worked and I couldn't fin a tutorial on this anywhere. Would be awesome if someone could link a tutorial or something :)

Edited by TorRS
Posted

Hello,

There are many ways of doing this. 

The Most Lazy Static Var of MethodProvider in Script

public class TopLevel extends Script {

    public static MethodProvider methodProvider;
    public void onStart() throws InterruptedException {
     methodProvider =this;
    }
....

Call it anywere with TopLevel.methodProvider

 

Lazy way when you make a new class hand it the MethodProvider and store it in the class like so

public class SomeClass{
    final MethodProvider mp;
    public SomeClass(final MethodProvider mp){
        this.mp = mp;
        
    }
    public void someMethod(){
        mp.getBank().open();
        
    }
}

 

The more "Professional" away were you extend MethodProvider and exchange Context.

 

public class SomeClass extends MethodProvider  {
 
}


 

public class TopLevel extends Script {

	MethodProvider something;
    public void onStart() throws InterruptedException {
  	something = 	new SomeClass();
   something.exchangeContext(getBot());
    }
....

 

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