Undo after selling a building doesn't undo the sale, and can lead to negative building count

Issue #174 new
Robin Munn created an issue

To reproduce:

  • Start a new game
  • Click ten times on Gather Catnip
  • Buy a catnip field
  • Watch undo counter tick down from 20 seconds
  • Wait five seconds, then sell catnip field, getting 5 catnip refunded. Undo counter is now at 15 seconds, and catnip field count is at 0
  • Click undo
  • Notice that 10 catnip was refunded, correctly.
  • BUT catnip field count is now at -1, and catnip amount is ticking down by -0.94/sec

It looks like selling a building doesn’t register an undo handler, so clicking on the undo link right after selling a building ends up undoing the initial purchase, which can result in building count going negative.

By buying and selling multiple buildings at once, you can get the building count to go to negative numbers further below zero, e.g. by accumulating a few hundred catnip via manual clicks, I managed to get down to a -9 catnip field count. To reproduce this:

  • Click on Gather Catnip until you have over a hundred catnip (exact amount doesn’t matter)
  • Shift-click on catnip field so you buy all the fields you can, all at once. In my case, I bought 9 fields.
  • Shift-click on sell button so you’re back at 0 catnip fields
  • Click the undo link. Now you’re at -9 fields (exact number may differ, but will be the number of fields you bought earlier times -1).

Suggestion for fixing: either selling a building should register an undo handler, or else selling a building should clear the undo handler that currently exists if (and only if) the current undo handler is the purchase of that building.

I note that in the undo function of buildings.js, there’s a console.warn(“Not implemented yet”) line for undoing a sale. I tested on Ver 1.4.7.0.a-α, 1.4.7.0.a-β, and 1.4.7.0.a-γ, and in all three of those versions, the “Not implemented yet” text never showed up in the Javascript console. So that code path isn’t getting hit, which suggests that selling buildings isn’t registering an undo handler at all (otherwise the if (data.action == "sell") code path in buildings.js should have been hit).

Comments (0)

  1. Log in to comment