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.

Java query regarding filters

Featured Replies

Hi, so in one of my previous scripts people mentioned I should try and use filters more:

The commented out code is what i was trying to do but was refusing to 'loot' the arrows.

The non-commented code works fine and i wondered if anyone new why the commented code didn't work?

// Filter<Item> arrows = item -> item.getName().contains("arrows");
 //GroundItem arrows1 = getGroundItems().closest(arrows.toString());
 GroundItem arrows1 = getGroundItems().closest("Bronze arrow","Iron arrow","Steel arrow","Mithril arrow","Adamant arrow");

Below is current version of my *arrows1*

GroundItem arrows1 = getGroundItems().closest(gi -> gi != null && getMap().canReach(gi) && gi.getName().contains("arrow"));

This one does work but is not using a filter (although it is kinda filtering by the contains name) but i wondered what would cause the toString() to not work as i wanted.

is arrows toString basically just writing down arrows. I though it should be writing down the whole Bronze arrow for example

31 minutes ago, scriptersteve said:

Hi, so in one of my previous scripts people mentioned I should try and use filters more:

The commented out code is what i was trying to do but was refusing to 'loot' the arrows.

The non-commented code works fine and i wondered if anyone new why the commented code didn't work?


// Filter<Item> arrows = item -> item.getName().contains("arrows");
 //GroundItem arrows1 = getGroundItems().closest(arrows.toString());
 GroundItem arrows1 = getGroundItems().closest("Bronze arrow","Iron arrow","Steel arrow","Mithril arrow","Adamant arrow");

Below is current version of my *arrows1*


GroundItem arrows1 = getGroundItems().closest(gi -> gi != null && getMap().canReach(gi) && gi.getName().contains("arrow"));

This one does work but is not using a filter (although it is kinda filtering by the contains name) but i wondered what would cause the toString() to not work as i wanted.

is arrows toString basically just writing down arrows. I though it should be writing down the whole Bronze arrow for example

 

Don't call toString()

closest() can take a Filter as a parameter.

Edited by Explv

38 minutes ago, scriptersteve said:

Hi, so in one of my previous scripts people mentioned I should try and use filters more:

The commented out code is what i was trying to do but was refusing to 'loot' the arrows.

The non-commented code works fine and i wondered if anyone new why the commented code didn't work?


// Filter<Item> arrows = item -> item.getName().contains("arrows");
 //GroundItem arrows1 = getGroundItems().closest(arrows.toString());
 GroundItem arrows1 = getGroundItems().closest("Bronze arrow","Iron arrow","Steel arrow","Mithril arrow","Adamant arrow");

Below is current version of my *arrows1*


GroundItem arrows1 = getGroundItems().closest(gi -> gi != null && getMap().canReach(gi) && gi.getName().contains("arrow"));

This one does work but is not using a filter (although it is kinda filtering by the contains name) but i wondered what would cause the toString() to not work as i wanted.

is arrows toString basically just writing down arrows. I though it should be writing down the whole Bronze arrow for example

If I'm not mistaken your current version of *arrows1* , is actually a filter. You're simply using some syntactical sugar to do it inline!

For reference below is what is really happening behind the scenes

GroundItem arrow = GroundItems.closest(new Filter<GroundItem>(){
  
  	public boolean match(GroundItem item){
  		return item != null && item.getName().contains("arrow") && Map.canReach(item);
  
  	}
  
  });

 

  • Author
36 minutes ago, withoutidols said:

If I'm not mistaken your current version of *arrows1* , is actually a filter. You're simply using some syntactical sugar to do it inline!

For reference below is what is really happening behind the scenes


GroundItem arrow = GroundItems.closest(new Filter<GroundItem>(){
  
  	public boolean match(GroundItem item){
  		return item != null && item.getName().contains("arrow") && Map.canReach(item);
  
  	}
  
  });

 

Thanks - that does help my understanding reading it though

Create an account or sign in to comment

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.