Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Inventory.getQuantity incompatible types

Joined
Feb 20, 2017
Messages
58
I'm declaring the name of the item as a string and using Inventory.getQuantity(String) to obtain the amount of said item in order to see how many are in my inventory. I'm getting the error "Incompatible types. Found: 'java.lang.Integer, required: boolean". I can't find a solution in the API and any help would be appreciated. Here is the code:
Code:
public boolean validate() {
        String thefoodofchoice = ("Monkfish");
        Integer howmany = Inventory.getQuantity(thefoodofchoice);
        if (howmany = 3){
            return true;
        }else{
            return false;
        }
    }
 
Joined
Oct 4, 2015
Messages
35
you're setting the value at line 4 instead of doing an equality check (and why declare a string and then use it if it's only used once?)
 
Joined
Feb 20, 2017
Messages
58
you're setting the value at line 4 instead of doing an equality check (and why declare a string and then use it if it's only used once?)
I'm a pretty big newb I must admit lol. Thank you for the pointer.

New code:
Code:
public boolean validate() {
        Integer howmany = Inventory.getQuantity("Monkfish");
        if (howmany == 3){
            return true;
        }else{
            return false;
        }
    }
 
Misfits
Joined
Nov 21, 2016
Messages
1,445
Code:
public boolean validate() {
        String thefoodofchoice = "Monkfish";
        Integer howmany = Inventory.getQuantity(thefoodofchoice);
        if (howmany == 3){
            return true;
        }
            return false;
    }

Altho the String should be defined in the main class, if will be used more then once
 
Joined
Feb 20, 2017
Messages
58
Code:
public boolean validate() {
        String thefoodofchoice = "Monkfish";
        Integer howmany = Inventory.getQuantity(thefoodofchoice);
        if (howmany == 3){
            return true;
        }
            return false;
    }

Altho the String should be defined in the main class, if will be used more then once
Because this specific class wont be imported into other classes I assume?
 
Misfits
Joined
Nov 21, 2016
Messages
1,445
Because this specific class wont be imported into other classes I assume?
this is a validate task, you are checking if there is 3 of String Monkfish, and if you need to use monkfish else where its better to build an encapsulated field in your main class rather then recreate it in every class
 
Joined
Aug 23, 2015
Messages
1,961
Is this more efficient? I wasn't sure how to use newQuery() in this case so I didn't attempt to.

By the way, your tutorials are the bomb :)
Queries make use of Java parallel streams. If you don't know what that means, just know it means it's very fast and efficient to use queries when possible.
 
Java Warlord
Joined
Nov 17, 2014
Messages
4,906
Yes they do.
Then why are they so scuffed? Why does a second .filter() call overwrite the first filter, or why can't we use the stream methods on the query/resultset?
Might as well expose the stream functionality to the bot author.
 
Perhaps explain what it is based on? ;)
Well apparently they indeed use java streams, but internally only unfortunately.
 
Client Developer
Joined
Oct 12, 2015
Messages
3,760
Then why are they so scuffed? Why does a second .filter() call overwrite the first filter, or why can't we use the stream methods on the query/resultset?

Oh, I see what you mean now. We don't extend the Stream functionality, but we do use it when loading results.
 
Java Warlord
Joined
Nov 17, 2014
Messages
4,906
Oh, I see what you mean now. We don't extend the Stream functionality, but we do use it when loading results.
Soooo any chance we could make it actually extend stream functionality?
Example would look like this:
Code:
Npc cow = Npcs.newQuery().names("Cow").actions("Attack").sorted(new DistanceComparator()).limit(3).peek(System.out::println).findAny().orElse(null)
Obviously that example is only a fragment of the possiblities this would give us :p
 
Client Developer
Joined
Oct 12, 2015
Messages
3,760
Soooo any chance we could make it actually extend stream functionality?
Example would look like this:
Code:
Npc cow = Npcs.newQuery().names("Cow").actions("Attack").sorted(new DistanceComparator()).limit(3).peek(System.out::println).findAny().orElse(null)
Obviously that example is only a fragment of the possiblities this would give us :p

I'm sure there was a discussion about this in Slack at some point and there was a reason we couldn't (or wouldn't), though I can't remember what that was off the top of my head.
 
Top