screepers / screeps-multimeter

The most useful tool on your screeps workbench.
MIT License
89 stars 28 forks source link

Watch plugin appears to not be working #16

Closed lee-dohm closed 4 years ago

lee-dohm commented 5 years ago

I installed the watch-client.js file in my code base as the instructions said. And I call it at the end of my game loop as can be seen in my Foreman.endShift() function which is called as the very last line in the loop.

Below is the console output from executing /watch status _.keys(Game.creeps).length as described in the documentation, along with some things that I did to try to debug the problem myself:

*** Cannot watch: Error: watch-client.js is not installed or out of date.                                                           
        at multimeter.api.memory.get.then.val (/Users/lee/Source/lee-dohm/screeps/node_modules/screeps-multimeter/plugins/watch.js:4
4:17)                                                                                                                               
        at process._tickCallback (internal/process/next_tick.js:68:7)
<<< JSON.stringify(Memory.watch)
>>> {"expressions":{},"values":{}}
<<< typeof Memory.watch
>>> object
<<< typeof Memory.watch.expressions
>>> object
*** This is Multimeter 1.8.0, which is the latest version.
<<< watcher = require("./watch-client")
>>> function () {
      if (typeof Memory.watch !== "object") {
        Memory.watch = {}
      }
      if (typeof Memory.watch.expressions !== "object") {
        Memory.watch.expressions = {}
      }
      if (typeof Memory.watch.values !== "object") {
        Memory.watch.values = {}
      }
      _.each(Memory.watch.expressions, (expr, name) => {
        if (typeof expr !== "string") return
        let result
        try {
          result = eval(expr)
        } catch (ex) {
          result = "Error: " + ex.message
        }
        if (name == "console") {
          if (typeof result !== "undefined") console.log(result)
        } else {
          Memory.watch.values[name] = typeof result !== "undefined" ? result.toString() : result
        }
      })
    }
CGamesPlay commented 5 years ago

Hey, thanks for reporting this issue! Unfortunately I haven't been involved in Screeps for a while so I'm not sure what might be causing this, but my suspicion is that it's something involving the screeps-api package (specifically, the socket API for accessing Screeps servers). Upgrading that version may resolve the issue. If you are interested in taking a look into this, please feel free to open a pull request.

Thanks!

pyrodogg commented 5 years ago

It looks like the format of the data returned from the api is different in getWatchExpressions, causing val.expressions to not exist. It should now be val.data.expressions. I'll do some more testing and submit a PR.

{ "ok": 1, "data": { "expressions": {}, "values": { "foo": "bar" } } }

CGamesPlay commented 5 years ago

Thanks for investigating, @pyrodogg. I'd be happy to accept a PR once you've confirmed.

pyrodogg commented 4 years ago

When I commented last week I had a fix working with screeps-api 1.7.2, which is the version currently used by screeps-multimeter. However, I also wanted to make sure it worked with latest version of screeps-api , which led down a rabbit hole resulting in a PR on that project.

The direct fix needed for screeps-multimeter doesn't change so I'll submit a PR for this with screeps-api 1.7.2.

Separately, I'll take a look at a PR to update the references including screeps-api once that patch is applied.

pyrodogg commented 4 years ago

A new version of screeps-api was pushed a few hours ago. Reinstall screeps-multimeter, and status bar watch should now be working correctly.