MarWo22 Posted February 18, 2019 Share Posted February 18, 2019 Im trying to make the piece of script to sell all the clean herbs i have in my inventory. I have an enum with all the herbs data. I've been trying to do it with a for loop but for some reason it doesn't work. If anyone could help me out that would be great Quote for(Herbs h : Herbs.values()) { if(mp.getInventory().contains(h.cleanName)) { if(mp.getGrandExchange().sellItem(h.cleanId, h.getCleanHerbPrice(), (int) mp.getInventory().getAmount(h.cleanName))) new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return !mp.getGrandExchange().isOfferScreenOpen(); } }.sleep(); } } Quote Link to comment Share on other sites More sharing options...
liverare Posted February 18, 2019 Share Posted February 18, 2019 MethodProvider You've got a variable for what I assume is the MethodProvider. You need to make sure that, before you use it, you call: mp.exchangeContext(bot) With the "bot" being passed in from the script. Herb enum Can you post your enum code? On the one hand, you have: h.getCleanHerbPrice() But on the other hand you're also doing: h.cleanName h.cleanId So it would be good to check to make sure you're calling stuff correctly. Script loop v.s. for-loop Your script already loops over and over again. It's safer to pick one herb per loop cycle and to just deal with that. That way, you avoid problems like having the bot try to drop a bunch of items in one go, only to then end up trying to drop an item that no longer exists. Quote Link to comment Share on other sites More sharing options...
ItPoke Posted February 18, 2019 Share Posted February 18, 2019 Look up the api, it says that you just specify an amount, no need to loop over them. That way you just sell one at a time. Also I would say change the if statement that checks if the inventory contains a clean herb and just do an inverse in the bank. So if the bank does not contain anymore dirty herbs, then widthdraw all clean herbs as noted, get the noted id for the herbs and sell them on the GE. I can give more specfic code examples if you need more help. Quote Link to comment Share on other sites More sharing options...
MarWo22 Posted February 18, 2019 Author Share Posted February 18, 2019 15 minutes ago, liverare said: Can you post your enum code? On the one hand, you have This is the enum im using. It uses a snippet to gather the prices for the items Quote public enum Herbs { GUAM_LEAF("Guam leaf", 3, 199, 249), MARRENTILL("Marrentill" , 5, 201, 251), TARROMIN ("Tarromin", 11, 203, 253), HARRALANDER ("Harralander", 20, 205, 255), RANARR_WEED ("Ranarr weed", 25, 207, 257), TOADFLAX ("Toadflax", 30, 3049, 2998), IRIT_LEAF ("Irit leaf", 40, 209, 259), AVANTOE ("Avantoe", 48, 211, 261), KWUARM ("Kwuarm", 54, 213, 263), SNAPDRAGON ("Snapdragon", 59, 3051, 3000), CADANTINE ("Cadantine", 65, 215, 265), LANTADYME ("Lantadyme", 67, 2485, 2481), DWARF_WEED ("Dwarf weed", 70, 217, 267), TORSTOL ("Torstol", 75, 219, 269); public String grimyName; public String cleanName; public int margin; public int lvl; public int grimyId; public int cleanId; Herbs(String herbName, int lvl, int grimy, int clean) { grimyName = "Grimy " + herbName.toLowerCase(); cleanName = herbName; this.lvl = lvl; margin = getCleanHerbPrice() - getGrimyHerbPrice(); grimyId = grimy; cleanId = clean; } public int getGrimyHerbPrice() { int price = 0; try { price = Math.max(ItemLookup.get(grimyName, Property.BUY_AVERAGE).map(Integer::parseInt).get(), ItemLookup.get(grimyName, Property.SELL_AVERAGE).map(Integer::parseInt).get()); } catch (Exception e) { price = -1; } return price; } public int getCleanHerbPrice() { int price = 0; try { price = Math.min(ItemLookup.get(cleanName, Property.BUY_AVERAGE).map(Integer::parseInt).get(), ItemLookup.get(cleanName, Property.SELL_AVERAGE).map(Integer::parseInt).get()); } catch (Exception e) { price = -1; } return price; } } Quote Link to comment Share on other sites More sharing options...
ItPoke Posted February 18, 2019 Share Posted February 18, 2019 Use a dynamic snippet instead so that you don't hardcode the prices. Quote Link to comment Share on other sites More sharing options...
liverare Posted February 18, 2019 Share Posted February 18, 2019 3 hours ago, MarWo22 said: This is the enum im using. It uses a snippet to gather the prices for the items Okay, so the enum isn't the problem. What about exchanging the bot context with the MethodProvider? Quote Link to comment Share on other sites More sharing options...