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
  • Standard object.interact method bugging when can't detect object


    Verify
     Share

    Recommended Posts

    Hi,

    I am trying to build a standard method that interacts how I want with an object I selected.

    public static void doThis (MethodContext Act, String Action, String Object) {
        if(!Act.getLocalPlayer().isAnimating()) {
            if(Act.getGameObjects().closest(ObjectFilter ->
                ObjectFilter != null &&
                ObjectFilter.hasAction(Action) &&
                ObjectFilter.getName().equals(Object)).interact(Action)) {
                sleep(1200);
            }
        }
    }

    The logic is that if there is a close-by object that is not null, has the option to perform the Action I want and has the same name as the Object I named, then it would interact with the Object with the specified Action. It works fine when there is such an object, but it stops the whole script when it can't find the object.

    I would like to know how it would be possible to just do nothing if no object is detected and to let the script continue to loop. I thought that is what I did by putting the whole Act.getGameObjects.closest ... in an IF statement, but that doesn't work.

    Link to comment
    Share on other sites

    You need to check if the object exists first:

    public static void doThis (MethodContext Act, String Action, String Object) {
        if(!Act.getLocalPlayer().isAnimating()) {
    		GameObject gameObject = Act.getGameObjects().closest(ObjectFilter ->
                ObjectFilter != null &&
                ObjectFilter.hasAction(Action) &&
                ObjectFilter.getName().equals(Object));
            if(gameObject != null && gameObject.interact(Action)) {
                sleep(1200);
            }
        }
    }
    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.