Bug - Fixed CLI command "buy 0 whatever" buys however many whatevers are currently in inventory

antimarty

Member
CLI command "buy 0 whatever" buys however many whatevers are currently in inventory

For example, "buy 0 seal-blubber candle" when you have 18004 in inventory buys another 18004 candles.

Luckily I caught that script before it doubled everything a few more times...

Obviously it's easy enough to check that I am actually planning to buy more than 0 of something, and not issue the command, but still.
 

icon315

Member
This might be a intentional behavior:
PHP:
kolmafia>persistence>ItemFinder.java
590: // Default to number in inventory if count was "*" (all) 
        // or negative (all but that many) and no list was given.
	matchCount = itemCount <= 0 ? firstMatch.getCount( KoLConstants.inventory ) : 1;
it says negative but it also counts 0 as well
 

Darzil

Developer
It's to do with the way Item Finder works. If it tries to find an item with 0 whatever, it defaults to returning the number in inventory. I've no idea why, but could break stuff if I change it, as Item Finder is used 100's of times in Mafia.

This way it breaks but is quickly fixed, and shouldn't break anything important I hope!

So my choices were a blunt check like this, changing Item Finder to potentially break other places where it was currently zero, or to carry on letting it double your inventory!

I guess I could have made it do nothing and not abort, but then anyone expecting current behaviour would be disappointed.
 
It's to do with the way Item Finder works. If it tries to find an item with 0 whatever, it defaults to returning the number in inventory. I've no idea why, but could break stuff if I change it, as Item Finder is used 100's of times in Mafia.

This way it breaks but is quickly fixed, and shouldn't break anything important I hope!

So my choices were a blunt check like this, changing Item Finder to potentially break other places where it was currently zero, or to carry on letting it double your inventory!

I guess I could have made it do nothing and not abort, but then anyone expecting current behaviour would be disappointed.

Seems like a reasonable approach then. Thanks for the explanation!
 
Top