Jump to content

Withdraw items in an array


sudoinit6

Recommended Posts

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 by sudoinit6
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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`!

 

Link to comment
Share on other sites

  • 1 year later...
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 by Glaciation96
Link to comment
Share on other sites

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 by Explv
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Explv
  • Like 2
Link to comment
Share on other sites

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