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
  • Master script in client calling other scripts


    Batko

    Recommended Posts

    Hi,

    Assume you have  two scripts, e.g., a Woodcutting and a Mining script. Is it possible to write another class which uses these given however you want it? I've read around the API and it seems that it is possible, however, I'm unsure where to start.
     
    Example:

    @ScriptManifest(author = "You", name = "Selector", version = 1.0, description = "Execute script orders", category = Category.WOODCUTTING)
    public class Selector extends AbstractScript {
    
      public void onStart() {
        log("Starting up");
      }
    
      public void onExit() {
        log("Closing down.");
      }
    
      @Override
      public int onLoop() {
    
        //1: Run WC script until custom termination
    
        //2: Run Mining script until custom termination
    
        //Kill the selector script
        return -1;
      }
    }

    The reason I want  to do this is that it leaves modularity to the original scripts since they can run stand-alone, but also provide flexibility to run from a main controlling script.

     

    Link to comment
    Share on other sites

    I personally just abuse quickstart to do this but there is probably a better way to do it
     


    I just call a new client instance while logging out with the new selected script.

    Link to comment
    Share on other sites

    Sure, but this still forces you to manually start each script, unless you program a bash script to run send your command line arguments.

    Link to comment
    Share on other sites

    Just figured out it is possible to start the other script through

    ScriptManager mg = new ScriptManager(getClient().getInstance());
    LocalLoader ll = new LocalLoader();
    for (java.lang.Class<? extends AbstractScript> script : LocalLoader.getScripts()) {
      if (script.getName().equalsIgnoreCase("Woodcutter")) {
        mg.start(script);
      }
    }

    where this loops through the local scripts and find the specified script name to start.

    However, my next question is how to pass any arguments while starting it this way? Assuming the onStart method has been overridden to accept arguments.

    Link to comment
    Share on other sites

    Continuing on the answer above, I've figured out that the API should be able to take in arguments in the following way

    mg.start("test1", "arg1","arg2","arg3");

    it compiles, runs, and starts the other script, however, the  onStart method  doesn't recognise the arguments I'm passing.

    Anyone else had this problem? Is it perhaps because I'm not VIP yet, and command line arguments/ starting scripts with arguments is for VIP and higher users?

    Link to comment
    Share on other sites

    56 minutes ago, Batko said:

    Continuing on the answer above, I've figured out that the API should be able to take in arguments in the following way

    
    mg.start("test1", "arg1","arg2","arg3");

    it compiles, runs, and starts the other script, however, the  onStart method  doesn't recognise the arguments I'm passing.

    Anyone else had this problem? Is it perhaps because I'm not VIP yet, and command line arguments/ starting scripts with arguments is for VIP and higher users?

    List<Class<? extends AbstractScript>> localScripts = LocalLoader.getScripts(); 

    Find the script by name and simply call the onStart method.

    script.onStart(args)
    ...
    loop
    ...
    script.onExit()

    And yes, I believe that quickstart is a VIP feature.

    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.