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
  • Try asking for help in the chatbox
  • Passing parameters with ScriptManager.start


    Terri_Farms
     Share

    Recommended Posts

    Hi All,

    I've been trying to write a script that is able to launch other scripts using the ScriptManager.start function.

    My current code has it starting the other script, but I want to be able to pass parameters to this newly launched script. This is the current code used to launch the new script:

    ScriptManager mg = new ScriptManager(getClient().getInstance());
    mg.start("IronMiner", "args", "test1", "test2");

    However, the new script does not seem to receive these arguments and only executes the onStart function that does not take arguments.

     

    Any help with this would be appreciated.

    Link to comment
    Share on other sites

        @Override
        public void onStart(String... params) {
            log("Started with params: " + params);
            for (String p : params) {
                log("Param found: " + p);
            }
            super.onStart(params);
        }

    does this work for the child script?

    Link to comment
    Share on other sites

    4 hours ago, thecloakdone said:
        @Override
        public void onStart(String... params) {
            log("Started with params: " + params);
            for (String p : params) {
                log("Param found: " + p);
            }
            super.onStart(params);
        }

    does this work for the child script?

    When the child script is called it doesn't call the onStart(String... params) method but the normal onStart() method.

    Link to comment
    Share on other sites

    10 minutes ago, Pandemic said:

    It''s happening because you're creating your own ScriptManager instead of using the one the client uses.

    Try starting it through ours (Instance#getScriptManager).

    Actually, the way he is doing it actually seems to run the script, just without the params.

    Doing it the way you suggest seems to not even launch it:

            MethodProvider.log("Starting script");
            getClient().getInstance().getScriptManager().start("ScriptName", "Test1", "123param");
            MethodProvider.log("Script launched");


    However, if you run a script with that code and then try to run the script you want to launch with the params manually, it starts it with the params you set in that code

     

     

    Link to comment
    Share on other sites

    16 hours ago, Pandemic said:

    It''s happening because you're creating your own ScriptManager instead of using the one the client uses.

    Try starting it through ours (Instance#getScriptManager).

    I've just tried using the client's ScriptManager:

    getClient().getInstance().getScriptManager().start("IronMiner", "params", "test1", "test2");

    But this doesn't launch the new script at all.

    Link to comment
    Share on other sites

    3 hours ago, Terri_Farms said:

    I've just tried using the client's ScriptManager:

    getClient().getInstance().getScriptManager().start("IronMiner", "params", "test1", "test2");

    But this doesn't launch the new script at all.

     

    You can use this code (its ugly and fucking weird but it will work)

            MethodProvider.log("Starting script");
            String scriptName = "ScriptName";
            String[] scriptParams = new String[] {"param1", "param2"};
            getClient().getInstance().getScriptManager().start(scriptName, scriptParams);
            ScriptManager m = new ScriptManager(getClient().getInstance());
            m.start(scriptName, scriptParams);
            MethodProvider.log("Script launched");

     

    Link to comment
    Share on other sites

    Yeah it won't start a script with one already running (the one calling it), it's another reason why you'll have to hack around to do it (like Neff suggests above). We currently don't have an official way to handle it, but I'll look into it for something we could do in DB3.

    Link to comment
    Share on other sites

    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
     Share

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