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.

listing item causing script to break

Featured Replies

Item strPot = getInventory().getItem("Strength potion(4)","Strength potion(3)","Strength potion(2)","Strength potion(1)");

The following line of code, causes my script to not even start even when i am not implementing it anywhere in the script just defining it at the beginning.

TRying to use it in the following scenario:-

 

 

if((getSkills().getDynamic(Skill.STRENGTH) - getSkills().getStatic(Skill.STRENGTH)) < pottingValue) {
    if(inventory.contains("Strength potion(4)","Strength potion(3)","Strength potion(2)","Strength potion(1)")){
        strPot.interact("Drink");
    }
    pottingValue = random(2,6);
}
45 minutes ago, scriptersteve said:

Item strPot = getInventory().getItem("Strength potion(4)","Strength potion(3)","Strength potion(2)","Strength potion(1)");

The following line of code, causes my script to not even start even when i am not implementing it anywhere in the script just defining it at the beginning.

TRying to use it in the following scenario:-

 

 


if((getSkills().getDynamic(Skill.STRENGTH) - getSkills().getStatic(Skill.STRENGTH)) < pottingValue) {
    if(inventory.contains("Strength potion(4)","Strength potion(3)","Strength potion(2)","Strength potion(1)")){
        strPot.interact("Drink");
    }
    pottingValue = random(2,6);
}

 

I'm assuming that strPot is defined as a member variable.

You can't do that, the API will not be setup yet.

The order is as follows:

  1. Static variables are initialised
  2. Member variables are initialised
  3. Constructor is called
  4. API context is exchanged
  5. onStart() is called
  6. onLoop() is repeatedly called until script exit

You are defining strPot as a member variable, if you look at the above list, you can see that it will be initialised before the API context is exchanged. This means that getInventory().getItem() will throw an NPE somewhere and your script will crash.

It doesn't make sense to do it there anyway, as it will only get a strength potion from your inventory once. If you then consumed that strength potion, that Item would  no longer exist and your script would fail. You need to call getInventory().getItem() every time you want to drink the potion. The code should be put inside of your if (inventory contains strength potion) check.

Side note:

You can make use of a Filter<Item> to reduce some code, for example:

private final Filter<Item> strPotionFilter = item -> item.getName().startsWith("Strength potion(");
    
public void someMethod() {
    Item strPotion = getInventory().getItem(strPotionFilter);
        
    if (strPotion != null) {
        strPotion.interact("Drink");
    }
}

 

Edited by Explv

  • Alek locked this topic
Guest
This topic is now closed to further replies.

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.