Jump to content

if (getInventory().isFull()) { Crashes script / NPE


Recommended Posts

Posted (edited)
if (this.api.store.isOpen()) {
            //Close shop and open packs
            if (getInventory().isFull()) {
                this.api.store.close();
            if (!getInventory().isItemSelected()) {
                getInventory().getItem(itemPack).interact("Open");
            new ConditionalSleep(10000) {
                @Override 
                public boolean condition() {
                return (!getInventory().isFull());
                }
            }.sleep();
            }
            }

This is what im trying to implement into my script. However, (getInventory().isFull()) breaks the script and floods log with NPE error.

I've found that it does this no matter where it is placed in my script.

 

I suppose an alternative would be 

(inventory.contains(itemPack) && inventory.getAmount(itemPack) >= )

but this would limit the scripts capabilities of purchasing more than 1 item at a time.

 

 

Help:gnome:

Edited by Chris050999
Posted
13 hours ago, Ragboys is back said:

Not sure if it's this but try to change


  public boolean condition() {
                return (!getInventory().isFull());
                }

to


  public boolean condition() {
                return !getInventory().isFull();
                }

AKA just remove the ( ) between the return line.

Did not and should not make a difference?
Not too sure haha.

 

13 hours ago, liverare said:

I'm assuming if you have to do


this.api.store.

then I'm guessing you also need to do


this.api.getInventory().isFull()

either way, look into this:

 

You are correct and I feel like a dummy for not realizing it myself.

Still causes a crash even if i call it outside of the class that uses api though, cant figure out why. This'll do for now though, thanks 😃

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...