sudoinit6 Posted May 11, 2017 Share Posted May 11, 2017 (edited) I am trying to create an array and if items in that array exist, withdraw them from the bank. If I create the array: String[] items = new String[] {"Coins", "Death rune"}; How do I withdraw any items that exist in the array from the bank? if (bank.isOpen()){ bank.withdrawAll(items); } this is the wrong answer ;) Anyone help me with the correct answer? Edited May 11, 2017 by sudoinit6 Quote Link to comment Share on other sites More sharing options...
harrypotter Posted May 11, 2017 Share Posted May 11, 2017 9 minutes ago, sudoinit6 said: I am trying to create an array and if items in that array exist, withdraw them from the bank. If I create the array: String[] items = new String[] {"Coins", "Death rune"}; How do I withdraw any items that exist in the array from the bank? if (bank.isOpen()){ bank.withdrawAll(items); } this is the wrong answer ;) Anyone help me with the correct answer? Use a HasMap: https://osbot.org/api/org/osbot/rs07/api/Bank.html#withdraw-java.util.HashMap- Pretty sure if you set the amount > the amount you have it will withdraw all. 1 Quote Link to comment Share on other sites More sharing options...
Acerd Posted May 11, 2017 Share Posted May 11, 2017 why not just do withdrawAll("Coins", "Death rune"); Quote Link to comment Share on other sites More sharing options...
The Undefeated Posted May 11, 2017 Share Posted May 11, 2017 String[] items = new String[] {"Coins", "Death rune"}; for (String i : items) { if (getBank().contains(i) { getBank().withdrawAll(i); } } 1 Quote Link to comment Share on other sites More sharing options...
sudoinit6 Posted May 11, 2017 Author Share Posted May 11, 2017 7 minutes ago, Acerd said: why not just do withdrawAll("Coins", "Death rune"); Because the actual list is going to be longer. 6 minutes ago, The Undefeated said: String[] items = new String[] {"Coins", "Death rune"}; for (String i : items) { if (getBank().contains(i) { getBank().withdrawAll(i); } } Danke`! Quote Link to comment Share on other sites More sharing options...
Glaciation96 Posted October 27, 2018 Share Posted October 27, 2018 (edited) On 5/11/2017 at 10:12 PM, The Undefeated said: String[] items = new String[] {"Coins", "Death rune"}; for (String i : items) { if (getBank().contains(i) { getBank().withdrawAll(i); } } Using this method, you're unable to single out an item from the array. You'll just withdraw everything in the array. Unless that is what you want, a method to pick out singular items from an array would be more useful surely? Would this work? String[] items = new String[] {"Coins", "Death rune"}; for (String i : items) { if (getBank().contains(i) { getBank().withdrawAll(i[0]); //For coins } } Edited October 27, 2018 by Glaciation96 Quote Link to comment Share on other sites More sharing options...
Explv Posted October 27, 2018 Share Posted October 27, 2018 (edited) 33 minutes ago, Glaciation96 said: Using this method, you're unable to single out an item from the array. You'll just withdraw everything in the array. Unless that is what you want, a method to pick out singular items from an array would be more useful surely? Would this work? String[] items = new String[] {"Coins", "Death rune"}; for (String i : items) { if (getBank().contains(i) { getBank().withdrawAll(i[0]); //For coins } } This post is a year old, not sure why you gravedigged it. Your code doesn't really make sense either (the whole point is to withdraw every item in the array, not a single one) Edited October 27, 2018 by Explv Quote Link to comment Share on other sites More sharing options...
Glaciation96 Posted October 27, 2018 Share Posted October 27, 2018 20 hours ago, Explv said: This post is a year old, not sure why you gravedigged it. Your code doesn't really make sense either (the whole point is to withdraw every item in the array, not a single one) I'm not intentionally looking for old posts, just digging through all the resources that I can find, then commenting to test my own understanding of java/botting lol. Also does my code not make sense or not work? So long as it's not the latter I'm happy He also asked for "any items" which I guess could translate to all or just some of the items, to me anyway. Nice Explv's Map btw, been using that loads. Quote Link to comment Share on other sites More sharing options...
dreameo Posted October 27, 2018 Share Posted October 27, 2018 5 minutes ago, Glaciation96 said: I'm not intentionally looking for old posts, just digging through all the resources that I can find, then commenting to test my own understanding of java/botting lol. Also does my code not make sense or not work? So long as it's not the latter I'm happy He also asked for "any items" which I guess could translate to all or just some of the items, to me anyway. Nice Explv's Map btw, been using that loads. no it doesn't make any sense lol. Quote Link to comment Share on other sites More sharing options...
Explv Posted October 27, 2018 Share Posted October 27, 2018 (edited) 1 hour ago, Glaciation96 said: I'm not intentionally looking for old posts, just digging through all the resources that I can find, then commenting to test my own understanding of java/botting lol. Also does my code not make sense or not work? So long as it's not the latter I'm happy He also asked for "any items" which I guess could translate to all or just some of the items, to me anyway. Nice Explv's Map btw, been using that loads. Well both really, there's a syntax error getBank().withdrawAll(i[0]); //For coins I assume that should be items[0] not i[0] But the code doesn't really make sense, if the bank contains "Death rune"s and not "Coins" you would still try to withdraw Coins. And you would never withdraw Death runes. If you wanted to withdraw any item from an array of items you could add a break after the withdraw in undefeated's code, or do something like: Arrays.stream(items) .filter(itemName -> getBank().contains(itemName)) .findAny() .ifPresent(itemName -> getBank().withdrawAll(itemName)); Edited October 27, 2018 by Explv 2 Quote Link to comment Share on other sites More sharing options...
Glaciation96 Posted October 28, 2018 Share Posted October 28, 2018 (edited) 3 hours ago, Explv said: Well both really, there's a syntax error getBank().withdrawAll(i[0]); //For coins I assume that should be items[0] not i[0] But the code doesn't really make sense, if the bank contains "Death rune"s and not "Coins" you would still try to withdraw Coins. And you would never withdraw Death runes. If you wanted to withdraw any item from an array of items you could add a break after the withdraw in undefeated's code, or do something like: Arrays.stream(items) .filter(itemName -> getBank().contains(itemName)) .findAny() .ifPresent(itemName -> getBank().withdrawAll(itemName)); Many thanks for the clarification! Gravedigging this thread turned out very beneficial to my understanding in the end EDIT: For the Array Stream, I'll have to come back to that in a few weeks time lol, but it's great to have it there for later reference. Edited October 28, 2018 by Glaciation96 Quote Link to comment Share on other sites More sharing options...