Jump to content

Scripting with classes


TorRS

Recommended Posts

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

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