Bug getCounter() returning inaccurate or less-than-ideal values

Recently I encountered an issue with getCounter in a script, and when investigating it, I dug up this:

> js getCounter("Vote Monster")

Returned: -2

> counters

Unexpired counters:
Vote Monster (9)

> js getCounters("Vote Monster", -2, -2)

Returned: Vote Monster

>js getCounters("Vote Monster", 0, 11)

returned: Vote Monster

No doubt you have noticed that 2+9=11. The fact that getCounters() has a value of both -2 and +9 for
the "Vote Monster" counter seems reasonable, but I feel like getCounter() should be returning 9, not -2.
 

heeheehee

Developer
Staff member
Why is the expired "Vote Monster" counter still around, I wonder?

getCounter as implemented today returns the first match it finds, with no guarantee that it's the best option.

That said, we could/should reject any expired matches, since they're no longer useful. In addition to properly clearing the expired Vote Monster counter.
 
Why is the expired "Vote Monster" counter still around, I wonder?

getCounter as implemented today returns the first match it finds, with no guarantee that it's the best option.

That said, we could/should reject any expired matches, since they're no longer useful. In addition to properly clearing the expired Vote Monster counter.
So sometimes expired matches are good; think about Romantic Monster Window End. You can get that window into the negatives through nowander zones and crafting and things like that, and having that counter exist in the negatives seems like a good thing.
 

heeheehee

Developer
Staff member
Ah, okay. So in this case, we'd want to deal with specifically Vote Monster which is apparently not being cleared appropriately.

Staring at the code now.

I'm very confused how we could possibly have two active counters for Vote Monster:
Java:
    if (TurnCounter.isCounting("Vote Monster")) {
      return;
    }

    int turns = 11 - ((KoLCharacter.getTurnsPlayed() - 1) % 11);
    TurnCounter.startCounting(turns, "Vote Monster", "absballot.gif");

(poking at impl of TurnCounter.isCounting) Did you ascend shortly before this?
 
Not shortly, but I hadn't fought a vote monster that day. I had finished a casual ascension, and only recently obtained my voterbadge.
 

heeheehee

Developer
Staff member
Okay. So, it looks like TurnCounter.isCounting only checks for unexpired counters.

The "Vote Monster" counter is typically cleared in QuestManager upon an appropriate encounter, but nowhere else (well, also when we reset all of our counters on ascension). This is potentially problematic -- if we didn't see the fight for whatever reason (e.g. failed to parse, or encountered outside Mafia), then we could end up with two Vote Monster counters, as you did.

A mildly inefficient but simple fix would be to add a stopCounting call inside VoteMonsterManager.
 
Top