Bug - Not A Bug buy(int, int, int) treats a price of less than 1 as infinite

The function in question: int buy(int qty , item it , int price)

The problem: Currently the function treats price < 1 as infinite. (I think. Maybe it just treats it as a very large number?)

That is to say that buy(500 , item , -1) will always buy 500 of the item. buy(500 , item , 0) will do the same thing.

I discovered this when I attempted to use this function to maintain a relatively stock of an item, by calling buy(500 , item , my_max_price - item_amount(item)). What I was shooting for is "The more of this item I possess, the less I'm willing to pay. The less I possess, the more I'm willing to pay." What I actually got is buying 500 of the item every time.

As a stopgap, I'm using buy(500 , item , max(my_max_price - item_amount(item), 1))

The fix: int buy(int qty , item it , int price) should never buy if price < 1.
 

Bale

Minion
Don't do that!

Just. Don't.

Try this:
Code:
if( my_max_price > item_amount(it))
   buy(500 , it , my_max_price - item_amount(it));

This is not a bug. Don't issue a buy command if you don't want to buy anything.
 
Well, okay, you can call it "not a bug". Maybe it's just "a function that sometimes behaves in a totally unintuitive way". Either way I think it would improve user experience if it were changed.

If I went to a store and said to the clerk, "I want to buy 500 apples, but only if your price is less than 1 cent apiece", and he responded by selling me 500 apples at $10 apiece, that would make no sense. Neither does this.

Many of Mafia's functions are designed to protect against this sort of unintended behavior. Including this one, in other scenarios! According to the wiki, "If qty is less than 1, the function will return true without purchasing anything." Following your argument, the function might as well just buy a million of the item if qty < 1. Because who would ever write a script that way? You should just externally check that qty >= 1 to protect the function from itself.
 
Last edited:

Bale

Minion
I'm certainly not the final arbiter of this function behaving as expected. If any of the devs disagree, then it will be changed.

However, lowering price limit to zero or less is obviously not the best way to not purchase an item.
 

Darzil

Developer
There was a bug. In the documentation "If a gty less than 1 is passed, the function will always buy qty, regardless of price", should read "If a price less than 1 is passed, the function will always buy qty, regardless of price.".

It now does.
 
Top