Jump to content

Help interacting with items


lnsomnia

Recommended Posts

Hello! I am very new to the osbot API and have limited experience in Java but am not at all new to coding in general. With that being said, I am having a hard time interacting with two items in my inventory. I am testing with buckets of water/clay and would simply like to interact with the two.

 

My case statement currently looks like this:

case MAKE_CLAY:
           log("Made it to case MAKE_CLAY");
            sleep(random(250,1200));
            if (getInventory().contains("Clay")) {
                log("Got the clay");
            }
            if (getInventory().contains("Bucket of water")) {
                log("Got the water");
            }
            getInventory().interact("Use", "Bucket of water");
            sleep(random(110,780));
            getInventory().interact("Use", "Clay");
            sleep(random(6000,1000));
            break;

I feel like I am following the documentation and my logs to check for the clay and water are reaching the debugger so I'm not sure what I'm doing wrong. Any help or advice for a newbie like me is appreciated :)

Link to comment
Share on other sites

32 minutes ago, lnsomnia said:

Hello! I am very new to the osbot API and have limited experience in Java but am not at all new to coding in general. With that being said, I am having a hard time interacting with two items in my inventory. I am testing with buckets of water/clay and would simply like to interact with the two.

 

My case statement currently looks like this:

case MAKE_CLAY:
           log("Made it to case MAKE_CLAY");
            sleep(random(250,1200));
            if (getInventory().contains("Clay")) {
                log("Got the clay");
            }
            if (getInventory().contains("Bucket of water")) {
                log("Got the water");
            }
            getInventory().interact("Use", "Bucket of water");
            sleep(random(110,780));
            getInventory().interact("Use", "Clay");
            sleep(random(6000,1000));
            break;

I feel like I am following the documentation and my logs to check for the clay and water are reaching the debugger so I'm not sure what I'm doing wrong. Any help or advice for a newbie like me is appreciated :)

not sure whats working and not with yours but..

if (getInventory().contains("Clay) && getInventory().contains("Bucket of water)) {
    if (getInventory().interact("Use, "Bucket of water")) {
          if (getInventory().interact("Use", "Clay")) {
               conditional sleep here
      }
}

conditional sleeps: https://osbot.org/forum/topic/127193-conditional-sleep-with-lambda-expressions/
 

Link to comment
Share on other sites

19 minutes ago, FuryShark said:

not sure whats working and not with yours but..

if (getInventory().contains("Clay) && getInventory().contains("Bucket of water)) {
    if (getInventory().interact("Use, "Bucket of water")) {
          if (getInventory().interact("Use", "Clay")) {
               conditional sleep here
      }
}

conditional sleeps: https://osbot.org/forum/topic/127193-conditional-sleep-with-lambda-expressions/
 

Thanks for the reply and help! The second if condition in your snippet is returning false for some reason :( dunno why I can't seem to interact with anything. I'm not even sure what to test at this point.

Link to comment
Share on other sites

getinventory.interact() is not a valid method.

Quote

        if (getInventory().contains("Clay") && getInventory().contains("Bucket of water")) {
            // We have both. lets use them
            if (getInventory().isItemSelected()) {
                // Item is selected in inventory
                if (!getInventory().getSelectedItemName().equals("Bucket of water")) {
                    // If, somehow, a different item is selected, deselect it
                    getInventory().deselectItem();
                } else {
                    // Bucket of water is currently selected item. Use it on clay
                    Item clay = getInventory().getItem("Clay");
                    if (clay != null && clay.interact("Use")) {
                        Timing.waitCondition(() -> getInventory().contains("Soft clay"), 2000);
                    }
                }
            } else {
                // Select the bucket of water
                Item bucket = getInventory().getItem("Bucket of water");
                if (bucket != null && bucket.interact("Use")) {
                    Timing.waitCondition(() -> getInventory().isItemSelected(), 2000);
                }
            }
        }

Link to extremely useful Timing methods

 

EDIT: Im incorrect, Inventory class extends ItemContainer so it does have the interact method

Edited by camaro 09
Link to comment
Share on other sites

On 10/22/2019 at 8:07 PM, camaro 09 said:

getinventory.interact() is not a valid method.

Link to extremely useful Timing methods

 

EDIT: Im incorrect, Inventory class extends ItemContainer so it does have the interact method

Oh dude! This is awesome, thanks! I really appreciate you taking the time to write that. Makes perfect sense too. Eclipse on the other hand is still yelling at me with some new errors so I'm gonna have to take a step further back and figure out what's wrong.  Probably need to study some more Java too. :/ Thank you!

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