Jump to content

Problem with my mining script


Recommended Posts

Posted (edited)

So I accidentally deleted my broken mining script and am trying to re-create it from memory, and so far so good. However I am trying to check the color of the rock before I mine it and I am missing something.

 

    public enum Rock {
        CLAY(6705),
        COPPER(4645),
        TIN(53),
        IRON(2576),
        SILVER(74),
        COAL(10508),
        GOLD(8885),
        MITHRIL(-22239),
        ADAMANTITE(21662),
        RUNITE(-31437);

        private final short COLOUR;

        Rock(final int COLOUR) {
            this.COLOUR = (short) COLOUR;
        }

        public boolean hasOre(final RS2Object object) {
            if (object == null || object.getDefinition().getModifiedModelColors() == null || !"Rocks".equals(object.getName())) {
                return false;
            }

            for (final short colour : object.getDefinition().getModifiedModelColors()) {
                if (colour == this.COLOUR) {
                    return true;
                }
            }
            return false;
        }
    }

    public void Minesomething() throws InterruptedException {
 
        goldRock = getObjects().closest( obj -> Rock.GOLD.hasOre(obj));
        if (goldRock != null && goldRock.interact("Mine")) {
            new Sleep(() -> isAnimating() || !Rock.GOLD.hasOre(goldRock), 10000).sleep();
        }

    }

 

That is the code I am having trouble with, It says can not resolve symbol goldRock. And I cant remember how I had it in my original working script. Any pointers?

 

Edited by loopback
typo
Posted (edited)

You haven't declared a goldRock variable. You're trying to reference it but it doesn't exist, thus the "Symbol cannot be found" error.

What you need to do is declare a variable of the same type as the return value from getObjects#closest. The return type is RS2Object, so the code should look like:
RS2Object goldRock = getObjects().closest( obj -> Rock.GOLD.hasOre(obj));

Edited by Easy
  • Like 1
Posted
18 minutes ago, Easy said:

You haven't declared a goldRock variable. You're trying to reference it but it doesn't exist, thus the "Symbol cannot be found" error.

What you need to do is declare a variable of the same type as the return value from getObjects#closest. The return type is RS2Object, so the code should look like:
RS2Object goldRock = getObjects().closest( obj -> Rock.GOLD.hasOre(obj));

This is it! Thank you I knew it was something obvious. This is what I get for cleaning my hard drive at 2am then trying to recreate something from memory. Thanks

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
  • Recently Browsing   0 members

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