Jump to content

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


Phoenix

Recommended Posts

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
Link to comment
Share on other sites

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 😃

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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