Bug use() returning incorrect values for Clara's Bell

phreddrickk

Active member
According to the wiki, use() should return false for items it fails to use.

> js use(Item.get("clara's bell"))

(usable quantity of Clara's bell is limited to 0 by daily limit)
Returned: true
 
Interesting. The "use" function returns the "continue value". That is "true" if KoLmafia is not in an ERROR state or "false" if it is.
For example:

Code:
    UseItemRequest.lastUpdate = "";
    if (!ConsumablesDatabase.meetsLevelRequirement(this.itemUsed.getName())) {
      UseItemRequest.lastUpdate = "Insufficient level to consume " + this.itemUsed;
      KoLmafia.updateDisplay(MafiaState.ERROR, UseItemRequest.lastUpdate);
      return;
    }

But daily limits do not apparently operate that way.

Code:
    int maximumUses = UseItemRequest.maximumUses(itemId, this.consumptionType);
    if (maximumUses < this.itemUsed.getCount()) {
      KoLmafia.updateDisplay(
          "(usable quantity of "
              + this.itemUsed
              + " is limited to "
              + maximumUses
              + " by "
              + UseItemRequest.limiter
              + ")");
      this.itemUsed = this.itemUsed.getInstance(maximumUses);
    }
Note that it prints a message, but it is not an ERROR.

This is followed by:

Code:
    if (this.itemUsed.getCount() < 1) {
      return;
    }

So it looks like specifically requesting to use 0 of an item and not specifying a count (which is the same as requesting 1 to be used) will both return without an error.

Interestingly enough, those checks are not at the top of the run() method; there are plenty of things we will attempt to "use" even if you don't have one or specifically ask for 0.

Code:
> ash use(1, $item[etched hourglass])

(usable quantity of etched hourglass is limited to 0 by daily limit)
Returned: true

> ash use(0, $item[etched hourglass])

Returned: true
 
Back
Top