Skip 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.

Help with looping inventory

Featured Replies

Hey guys sorry im rushed n looking for a quick answer i have this loop

	while (this.inventory.contains(new String[] { "Ferret" })){
    		for (Item fr : inventory.getItems()) {   			
    			if (fr.getId() == 10092) {
    				fr.interact("Release");
    				sleep(random(500, 600));
    			}
    		}
    	}

 and instead of going to the item it just sits there i tired debugging it but im strapped for time anyone run into this before?

  • Author

Remove the first line and see if that works.

 

Tired just it before posting and it didnt i added the while loop to see if it wasn't trying to do one and then getting the state again but still nothing

Do you get any errors? Check the console.

 

According to the API docs the array returned by getItems() may contain null elements so you should check for that, otherwise your ID check will throw NullPointerException.

if(inventory.contains(10092)//assuming ferret id is 10092
inventory.interact("Release",10092);


Not sure if that's what you wanted or not, but I feel ilke that's what I read. so long as you have 10092 in your inventory it will go through this until your dont.

Edited by twin 763

  • Author
if(inventory.contains(10092)//assuming ferret id is 10092
inventory.interact("Release",10092);


Not sure if that's what you wanted or not, but I feel ilke that's what I read. so long as you have 10092 in your inventory it will go through this until your dont.

 

 

tired but it freaks out does one then just jumps along the others and is very slow. error is with the fr.getid equalling 10092 and yes using 10092 ids the ferrets inventory id

You in need to null check the itemfr in the for loop before checking Id. if(fr != null)

Hope this helped :)

The script already runs on a loop, so my modified version of your code should work :)

 

Hey guys sorry im rushed n looking for a quick answer i have this loop

	while (this.inventory.contains(new String[] { "Ferret" })){
    		for (Item fr : inventory.getItems()) {   			
    			if (fr.getId() == 10092) {
    				fr.interact("Release");
    				sleep(random(500, 600));
    			}
    		}
    	}

 and instead of going to the item it just sits there i tired debugging it but im strapped for time anyone run into this before?

                for (Item fr : inventory.getItems()) {   			
    			if (fr.getName().equals("Ferret")) {
    				fr.interact("Release");
    				sleep(random(500, 600));
    			}
    		}

Edited by Valkyr

The script already runs on a loop, so my modified version of your code should work :)

for (Item fr : inventory.getItems()) {   			    			if (fr.getName().equals("Ferret")) {    				fr.interact("Release");    				sleep(random(500, 600));    			}    		}
shouldn't you include a null check on fr? Because he says it is throwing an error where is checks the id which would lead me to believe it is an NPE. I may be wrong :)

Precise

  • Author

 

The script already runs on a loop, so my modified version of your code should work smile.png

                for (Item fr : inventory.getItems()) {   			
    			if (fr.getName().equals("Ferret")) {
    				fr.interact("Release");
    				sleep(random(500, 600));
    			}
    		}

This worked out perfect I kinda had an idea to use the name but i went with id, I see this api is slightly different than i've scrip[ted before but thanks to the community I hope to get the hang of it fast! Thank you Valk

 

shouldn't you include a null check on fr? Because he says it is throwing an error where is checks the id which would lead me to believe it is an NPE. I may be wrong smile.png

Precise

IT wouldn't execute as the condition of state checks for  the item before executing

 
for(int i = 0; i < 28; i ++){
    item = instance.inventory.getItemInSlot(i);
    if(item == null) continue;

         instance.inventory.interact(i, "Drop");
         for(int temp = 0; temp < i; temp ++){ //This part of the method should counter
             Item tempItem = instance.inventory.getItemInSlot(temp); // items being skipped due to unknown causes, presumably lag.
             if(tempItem != null)){
                   MethodProvider.sleep(MethodProvider.random(200,400));
                   inventory.interact(temp, "Drop");
}
}
}
}

You can probably change this around a bit, but what it does is goes back when items are accidentally skipped due to lag, instead of looping through the entire inventory, then checking if there are items left over. Snippet I provided is not very bot like.

 

Just add the ferret check line, and you should be all G

Edited by Mykindos

  • Author
 
for(int i = 0; i < 28; i ++){
    item = instance.inventory.getItemInSlot(i);
    if(item == null) continue;

         instance.inventory.interact(i, "Drop");
         for(int temp = 0; temp < i; temp ++){ //This part of the method should counter
             Item tempItem = instance.inventory.getItemInSlot(temp); // items being skipped due to unknown causes, presumably lag.
             if(tempItem != null)){
                   MethodProvider.sleep(MethodProvider.random(200,400));
                   inventory.interact(temp, "Drop");
}
}
}
}

You can probably change this around a bit, but what it does is goes back when items are accidentally skipped due to lag, instead of looping through the entire inventory, then checking if there are items left over. Snippet I provided is not very bot like.

 

Just add the ferret check line, and you should be all G

 

 

Thanks kindo may need this now because it will jsut randomly stop on items that arent the ferret n sit there haha!!!

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

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.