Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

eat anything edible in inventory

Featured Replies

Why is this not working, it only eats the item in the first inventory slot.

public boolean eat() {
if (!foodInInv) {
Mylog("No food in inventory.");
return false;
}


Item[] invItems = getInventory().getItems();
if (invItems != null) {
for (int i = 0; i < 28; i++) {
Mylog(Integer.toString(i));
if (invItems[i].getName() != null) {
Mylog("test");
String[] itemActions = invItems[i].getDefinition()
.getActions();
Mylog("test 1");
for (int ii = 0; ii < itemActions.length; ii++) {
Mylog("test 2");
if (itemActions[ii].equalsIgnoreCase("Eat")) {
Mylog("test 3");
if (invItems[i].interact("Eat")){
return true;
}
Mylog("test 4");
}
Mylog("test 5");
}


}
Mylog("No item at this inv slot: " + i);
}
}
foodInInv = false;
Mylog("No food in inventory.");
return false;
}

this is the log i get:

[iNFO][bot #1][06/03 01:54:29 PM]: 0
[iNFO][bot #1][06/03 01:54:29 PM]: test
[iNFO][bot #1][06/03 01:54:29 PM]: test 1
[iNFO][bot #1][06/03 01:54:29 PM]: test 2

Edited by fre024

It's because you return after eating an item, if you want to return true if at least one item was eaten then hold it in a boolean variable until the loop has finished then return the result

There's no need to complicate it as much as you have either. Something like:

private boolean eat() {
        for (Item i : getInventory().getItems()) {
            if (i != null && Arrays.asList(i.getDefinition().getActions()).contains("Eat"))
                return getInventory().interact(i.getId(), "Eat");
        }
        return false;
    }

Should work.

Edited by Pseudo

There's no need to complicate it as much as you have either. Something like:

private boolean eat() {
        for (Item i : getInventory().getItems()) {
            if (i != null && Arrays.asList(i.getDefinition().getActions()).contains("Eat"))
                return getInventory().interact(i.getId(), "Eat");
        }
        return false;
    }

Should work.

 

This is all you need ^

 

Also, press ctrl+shift+f :)

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.