Jump to content

Problem with my mining script


loopback

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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