There is no need to do widgets.bank, it is the same instance as bank. That code will of course not work, because at the moment the interact method returns the interface is not open so the code between the while block is never executed.
pseudo code
if booth.interact("Bank") {
// wait for the bank to be open
new ConditionalSleep... {
boolean { return bank.isOpen }
}.sleep
// perform banking logic here
if (logic performed correctly) {
close bank
conditional sleep to make sure bank is closed
continue what you want to do
}
There is a method in the API to open banks, you know that right?This is the actual code:
/**
* Searches for the best bank, based on type and distance from player. This
* method will only interact with RS2Objects.
*
* @return If bank was already open, or opened successfully.
*/
public boolean open() throws InterruptedException {
if (isOpen())
return true;
final RS2Object bankObject = bot.getMethods().objects.closest(
new NameFilter<RS2Object>("Bank booth", "Bank chest"),
new ActionFilter<RS2Object>("Bank", "Use"));
if (bankObject != null && map.canReach(bankObject)) {
Event event = new InteractionEvent(bankObject, "Bank", "Use");
execute(event);
if (event.hasFinished()) {
return new ConditionalSleep(5000) {
@Override
public boolean condition() throws InterruptedException {
return isOpen();
}
}.sleep();
}
}
return isOpen();
}