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
  • If Statement error?


    beefsteak
     Share

    Recommended Posts

    Heyo, working on a simple script that fights mobs on Karamja and banks at Port Sarim depot box. Having some issues with this if statement for paying the seaman/customs officer. I thought I'd just need to add a parentheses, but when I do it makes a ton of other errors pop up. Also, my filter is fucked up, not sure if thats affecting this at all. 

    Line 98 error: "syntax error, insert ") statement" to complete IfStatement"
    Filter error:  "must implement the inherent abstract method Filter<NPC>.match<NPC>"

    NOOB CODER HERE, PLEASE SHAME ME AND MY LACK OF CODING SKILLS

    Thanks
     

    HMonkeys_shot6.PNG

    HMonkeys_shot3.PNG

    Edited by beefsteak
    Added error messages
    Link to comment
    Share on other sites

    I would highly recommend an IDE such as IntelliJ, as it helps to tell you what's wrong with your code and gives suggestions :)

     

    Why would you want to check if you, the local player is not null? Also that line is missing a ')' after the:

    getGameObjects().closest("Gangplank") != null) <--
    

     

    You could use:

    getGameObjects().closest(plank -> plank != null && plank.hasAction("Cross"));

     

    For your dialogue part you could condense it down a bit to this, also a friendly reminder to use the java naming conventions, just makes it easier for others to read when using the standards. This is an adaptation of your second dialogue:

    if (port2Area.contains(getLocalPlayer()) && sailor2 != null) {
        if (getDialogues().inDialogue()) {
            getDialogues().spaceToContinue();
            getDialogues().chooseOption("Can I journey on this ship?");
        } else {
            NPC sailor2 = getNpcs().closest("Customs officer");
            sailor2.interact("Pay-fare");
            sleepUntil(() -> getDialogues().inDialogue(), 8000);
    }
    

     

    You could condense your entire dialogue into one very similar to this ^ just add the other option from the other sailor dialogue under "Can I journey on this ship?" and it will cycle through until it finds that option. It will skip the irrelevant options. 

    You would also need to probably do something like, if in port1Area OR port2Area, and if the sailors are not null (always null check) then if in dialogue, do the dialogue, if not, initiate conversation and wait until in conversation. There are probably better ways of doing this, but I have found success with this method.

     

    Also are you trying to fight the monkeys? What are you trying to script regarding them?

    Good luck! 

    Edited by Xtra
    Link to comment
    Share on other sites

    GameObject plank = getGameObjects.closest(p -> p != null && p.hasAction("Cross"));
    if(plank.exists()){
    	plank.interact("Cross");
    	sleepUntil(() -> !getLocalPlayer.isAnimating());
    }
    break;

    Like ^ said, this should work and is decently formatted
    Edit:
    Wanted to add for learning purposes, 
    Your debugger says specifically, syntax error, insert ") statement" to complete ifStatement
    and the red line shows where it expects a ) to be, or if there's one ) extra, the red line appears where it should not be

    Also: figured out the other issue, your NPC filter is missing code that needs to be there to use new Filter<foo>

    This is what a completed Filter<foo> should look like:
     

    public static final Filter<Item> HIDE_FILTER = new Filter<Item>() {
            @Override
            public boolean match(Item item) {
                if (item == null) {
                    return false;
                }
                return item.getName().equals(COWHIDE); //Checks i item equals Cowhide
            }
        }

    you must include an @Override and the boolean "match(Foo bar){}"
    Replace "Item" with NPC and it should be fine

    Edited by Auroch
    Link to comment
    Share on other sites

    Wow okay thank you this is verrrry helpful. Struggled with streamlining the code, I figured there was a lot of unnecessary stuff in there. Appreciate it! And yes, its going to be a simple monkey killing script, definitely not working at the moment but still trying to fix a few more kinks with the state selection part. 

    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.