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.

Items and Inventory.

Featured Replies

Scenario: Our backpack contains coins in slot 1, Diamond in slot 2, Gold necklace in slot 3, empty other than that.

 

I am trying to loop through the backpack slots and do something if the slot contains coins, something else if the slot contains something else and just increment the counter if the item is null.

 

Here is my code:

 

int x = 1;
		totalVal = 0;
		while (x < 29) {
			Item curItem = api.getInventory().getItemInSlot(x);
			api.log("Current item is " + curItem);
			String valueItemName = curItem.getName();
			api.log("valueItemName is " + valueItemName);
			if (valueItemName == "Coins") {
				api.log("Coins are a match");
				x = x + 1;

				MethodProvider.sleep(rnd3);
			}else if (curItem != null && valueItemName != "Coins") {
				buyItemId = 0;
				for(Map.Entry entry: stuff.entrySet()){
		            if(valueItemName.equals(entry.getValue())){
		                buyItemId = (int) entry.getKey();
		                break; //breaking because its one to one map
		            }
		        }
				api.log("item is " + valueItemName);
				api.log("item id is " + buyItemId);
				
				x = x + 1;
				api.log("Item is not null, adding one to x. x now equals " + x);
				MethodProvider.sleep(rnd3);
			} else {
				x = x + 1;
				api.log("Item is null, adding one to x. x now equals " + x);
				MethodProvider.sleep(rnd3);
			}
	
			
			
		}

The only one that seems to be working is the second check, I am getting nothing on "Coins" and nothing on null. Here is the log:

 

[INFO][Bot #1][04/30 10:49:29 PM]: Current item is Item id: 1602, Name: Diamond, Amount: 50
[INFO][Bot #1][04/30 10:49:29 PM]: valueItemName is Diamond
[INFO][Bot #1][04/30 10:49:29 PM]: item is Diamond
[INFO][Bot #1][04/30 10:49:29 PM]: item id is 1601
[INFO][Bot #1][04/30 10:49:29 PM]: Item is not null, adding one to x. x now equals 2
[INFO][Bot #1][04/30 10:49:37 PM]: Current item is Item id: 1655, Name: Gold necklace, Amount: 1080
[INFO][Bot #1][04/30 10:49:37 PM]: valueItemName is Gold necklace
[INFO][Bot #1][04/30 10:49:37 PM]: item is Gold necklace
[INFO][Bot #1][04/30 10:49:37 PM]: item id is 1654
[INFO][Bot #1][04/30 10:49:37 PM]: Item is not null, adding one to x. x now equals 3
[INFO][Bot #1][04/30 10:49:45 PM]: Current item is null

Then the loop breaks and starts over. Are "Coins" somehow a different item? Why wont this fall through to the third "if"?

 

  • Author
Just now, Gunman said:

Inventory slots start at 0 not 1.

Well, that would explain why it is skipping coins, thanks a lot for that! 

Now about breaking the loop when the item is null?

  • Author
Just now, Gunman said:

break;

 

I want it to NOT break, it is breaking and starting over when the item is null.

5 minutes ago, sudoinit6 said:

I want it to NOT break, it is breaking and starting over when the item is null.

String valueItemName = curItem.getName();

Stuff like that will cause an NPE and break it since curItem is null. Null check bro

EDIT: What you should do is null check curItem after declaring it so you won't have to null check it again.

Edited by Gunman

  • Author
3 minutes ago, Gunman said:

String valueItemName = curItem.getName();

Stuff like that will cause an NPE and break it since curItem is null. Null check bro

EDIT: What you should do is null check curItem after declaring it so you won't have to null check it again.

OK, that makes sense. I am not a very experienced coder. So how do I make it do something if it IS null? Oh, I just had a thought. Check the slot for empty, if not empty do stuff, if it is empty then increment the counter. Does that make sense?

 

  • Author
3 hours ago, Khaleesi said:

I'm not sure what you are trying to do here, but there are probably better ways of doing this.
What's the initial idea behind this?

Oh I am SURE there are better ways to do it, but here is what I am trying to do:

Get the value of each item in inventory add the number of coins and print out the total value.

I got it working with the above help, (had to tweak the pastebin a little) but you guys know way more than I do so I am open to suggestions to improve.

 

 

Edited by sudoinit6

  • Developer
4 hours ago, sudoinit6 said:

Oh I am SURE there are better ways to do it, but here is what I am trying to do:

Get the value of each item in inventory add the number of coins and print out the total value.

I got it working with the above help, (had to tweak the pastebin a little) but you guys know way more than I do so I am open to suggestions to improve.

 

 

Oh I see :)
That's good, if you need anything else you can always ask me

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.