Problems with using the cli-command buy in a script

Winterbay

Active member
I tried having a script function that buys up to 5 of a number of things if I have less and not otherwise. The call looked like this:

Code:
 cli_execute("buy " + (5 - item_amount($item)) + " " + $item);

where $item is exchanged for whatever it is I want to buy atm.

I thought it would stop buying things when I had 5 or more but it appears to not do this. I then tried some different commands and realised that if you send a negative amount or 0 to buy it will do odd things.

Code:
> buy -1 bottle of gin

buy 9 bottle of gin for 151 each from 809809 on 20100812
You acquire bottle of gin (9)

---

> ash cli_execute("buy " + max(0,-1) + " bottle of gin");

buy 19 bottle of gin for 151 each from 809809 on 20100812
You acquire bottle of gin (19)

Is this the intended behaviour?
 

Bale

Minion
In CLI commands it is standard for 0 to mean as many as possible and a negative number to mean all possible, except for that many. So, yeah, I'm not surprised that got messed up.

In other news, You should really consider using the buy() command when you're using ash, instead of cli_execute(). It wouldn't have had that problem, though max() is still better programming practice.
 

Winterbay

Active member
Ahh, right. I ended up with only calling the cli_execute if a if-statment concluded that the amount was less than 5.

Would "buy(-1, bottle of gin)" (or 0) lead to none being bought or give the same result as that above?
 
Top