May 11, 20178 yr 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, 20178 yr by sudoinit6
May 11, 20178 yr 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.
May 11, 20178 yr String[] items = new String[] {"Coins", "Death rune"}; for (String i : items) { if (getBank().contains(i) { getBank().withdrawAll(i); } }
May 11, 20178 yr Author 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`!
October 27, 20187 yr 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, 20187 yr by Glaciation96
October 27, 20187 yr 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, 20187 yr by Explv
October 27, 20187 yr 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.
October 27, 20187 yr 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.
October 27, 20187 yr 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, 20187 yr by Explv
October 28, 20187 yr 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, 20187 yr by Glaciation96
Create an account or sign in to comment