Bug - Not A Bug Eat, make, closet and probably other commands as well are "broken" for 0 and negative numbers

Lacey Jones

New member
So if you pass 0 it will try to eat, make or closet one more than all you have, negative numbers will count backwards:

> eat 0 cal sau (usable quantity of magical sausage (351) is limited to 0 by daily limit) > eat -1 cal sau (usable quantity of magical sausage (350) is limited to 0 by daily limit) > closet put 0 magical sausage casing Placing items into closet... Transfer failed for magical sausage casing (344) > /count magical sausage casing You have 343 magical sausage casings. > closet put -1 magical sausage casing Placing items into closet... Requests complete. > make 0 cal sau Creating 344 magical sausage... Requests complete.

Thankfully the code preventing my mistake of grinding 13mil meat in sausages is now protected, but who knows what kind of other places where this might break and do some harm to someone. And if this was intended behaviour, it's kind of an evil intended behaviour 😈
 

Veracity

Developer
Staff member
In many places, "0" intentionally means "as many as possible".
Perhaps it could/should have used "*" or something.
 

Lacey Jones

New member
In many places, "0" intentionally means "as many as possible".
Perhaps it could/should have used "*" or something.
"*" works for as many as possible just fine...
0 is actually trying to make 1 more than the max, with -1 meaning max, -2 is max but one etc, akin to python lists or something like that
 

fronobulax

Developer
Staff member
As a philosophy discussion only, but shouldn't be the case that passing a negative number to any of these commands should be rejected? If there was a regurgitate option "eat -1 ..." might do something "reasonable" but as things are now, I don't know what to expect.

I understand giving zero a special meaning because it is easier to coerce input to integers than to test for a special case and coerce if the special is not.

After five minutes it was not obvious to me where zero was being converted to max avail and then off by one but I should look harder.
 

heeheehee

Developer
Staff member
ClosetCommand uses persistence/ItemFinder.java which implements this logic in several places (getMatchingItemList calls getFirstMatchingItem -- just search for `<= 0`).

Can you reproduce across logins? How many magical sausage casings did Mafia itself think you have? (`inv magical sausage casing`)

My suspicion, seeing as I can't reproduce, is that Mafia's inventory tracking was out of sync.
 

Lacey Jones

New member
Okay I tested again and yes, it was out of sync, still remains the fact that `0` works just like `*` and negative numbers also work as I mentioned, counting backwards from the maximum available, still seems like wrong behaviour to me.
 

heeheehee

Developer
Staff member
For better or worse, this is intended behavior.

If you don't want this special handling, you're welcome to use ASH (without cli_execute), but the gCLI is intended for manual input, and we'd like to preserve the ability to say, for instance, "sell all but 1 of this item".
 
Top