Jump to content

Script with multiple files


SXForce

Recommended Posts

I am trying to create a larger script than usual, so I want to use multiple files for it.

 

Now I have the main script that starts up, but I have to use the methods of "MethodProvider" in the OSBot API in the other class too. Something like:

 

MainScript.java

private DoWalkPath path;

@Override
public void onStart() {
   path = new DoWalkPath(); // This is just an example name, I don't want the other class just to walk...
}

@Override
public int onLoop() throws InterruptedException {
    switch (state) {
        case WALKING_TO_BANK:
        path.walk(); // This is what I want
        break;
    }
    return 3;
}

DoWalkPath.java

public void walk() {
    openTab(Tabs.Magic);
    selectInterfaceOption(271, 23, "Cast"); // Teleport or something
    sleep(random(5000, 6000)); // Wait for teleport
    walk(Position); // Walk from there
}

Now I can't use "walk()" as I don't have access to the MethodProvider in that other class.

 

I tried extending the MethodProvider, but I every value is null (client etc).

Edited by SXForce
Link to comment
Share on other sites

You have to pass object that uses Method provider, Script  class extends it so you can use it. Make a constructor in you DoWalkPath class which takes Script as a parameter something like this

public DoWalkPath(Script script) {
     this.script = script;
}

and to initiate it in the main calss just simplu make an DoWalkPath and pass to it the parameter script(Main class)

public DoWalkPath walk = new DoWalkPath(this);

Hope this helps.

Link to comment
Share on other sites

You have to pass object that uses Method provider, Script  class extends it so you can use it. Make a constructor in you DoWalkPath class which takes Script as a parameter something like this

public DoWalkPath(Script script) {
     this.script = script;
}

and to initiate it in the main calss just simplu make an DoWalkPath and pass to it the parameter script(Main class)

public DoWalkPath walk = new DoWalkPath(this);

Hope this helps.

 

Yeah, just did this and it works. Thanks for the answer.

 

Isn't there another way where i dont have to pass the entire class? :P

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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