barackogama Posted August 9, 2018 Posted August 9, 2018 Probably a very simple solution but I can't seem to find it while searching through osbot API. I simply want to use an item on another (for example using a needle on leather or knife on logs). I found the following method but how do I make it click on a certain item after? getInventory().getItem("Needle").interact("Use") Thankful for answers.
Token Posted August 9, 2018 Posted August 9, 2018 Interact with the second item after interacting with the first one 1
barackogama Posted August 9, 2018 Author Posted August 9, 2018 4 minutes ago, Token said: Interact with the second item after interacting with the first one Would this work? getInventory().getItem("Knife").interact("Use"); getInventory().getItem("Log").interact();
Token Posted August 9, 2018 Posted August 9, 2018 11 minutes ago, barackogama said: Would this work? getInventory().getItem("Knife").interact("Use"); getInventory().getItem("Log").interact(); You can always try it, but make sure you add some sleep between them 1
Explv Posted August 9, 2018 Posted August 9, 2018 2 hours ago, barackogama said: Probably a very simple solution but I can't seem to find it while searching through osbot API. I simply want to use an item on another (for example using a needle on leather or knife on logs). I found the following method but how do I make it click on a certain item after? getInventory().getItem("Needle").interact("Use") Thankful for answers. if (!"Needle".equals(getInventory().getSelectedItemName())) { if (getInventory().isItemSelected()) { getInventory().deselectItem(); } else { getInventory().interact("Use", "Needle"); } } else if (getInventory().getItem("Leather").interact()) { new ConditionalSleep(2000) { @Override public boolean condition() throws InterruptedException { return getWidgets().getWidgetContainingText("Choose a quantity, then click an item to begin") != null; } }.sleep(); } 1
liverare Posted August 9, 2018 Posted August 9, 2018 I wrote this ad-hoc and untested function: public boolean useItemOnItem(String itemA, String itemB) throws IllegalArgumentException, RuntimeException { /* Variables */ boolean successful = false; String selectedItemName; /* Validation */ if (itemA == null || itemA.isEmpty()) { throw new IllegalArgumentException("Parameter \"itemA\" is invalid!"); } else if (itemB == null || itemB.isEmpty()) { throw new IllegalArgumentException("Parameter \"itemB\" is invalid!"); } else if (itemA == itemB) { throw new IllegalArgumentException("Parameter \"itemA\" and \"itemB\" must be different!"); } else if (!inventory.contains(itemA)) { throw new RuntimeException("Inventory doesn't contain: " + itemA); } else if (!inventory.contains(itemb)) { throw new RuntimeException("Inventory doesn't contain: " + itemB); } /* Process */ selectedItemName = inventory.getSelectedItemName(); if (selectedItemName != null) { if (selectedItemName == itemA) { /* Now click on item B */ successful = inventory.getItem(itemB).interact(); } else if (selectedItemName == itemB) { /* Now click on item A */ successful = inventory.getItem(itemA).interact(); } else { /* Deselect and then re-try (safe recursion) */ if (inventory.deselectItem()) { useItemOnItem(itemA, itemB); } else { throw new RuntimeException("Failed to deselect: " + selectedItemName); } } } else { /* Select item and re-try (safe recursion) */ if (inventory.interact("Use", itemA)) { successful = useItemOnItem(itemA, itemB); } else { throw new RuntimeException("Failed to select: " + itemA); } } return successful; } Then you could do: try { if (useItemOnItem("Needle", "Thread")) { /* Conditional sleep */ } } catch (IllegalArgumentException e) { /* I should have checked we have items before executing the function */ } catch (RuntimeException e) { /* Something bad happened... */ }
barackogama Posted August 11, 2018 Author Posted August 11, 2018 (edited) Is there a simple way to not always interact with the first item found with the Interact-methods? Ty for the help btw, I applied your solutions to my code and it's working well, Edited August 11, 2018 by barackogama