Coder Social home page Coder Social logo

Comments (6)

CapacitorSet avatar CapacitorSet commented on June 9, 2024

I can't reproduce this. Can you include your options for Redis and Rebridge - or alternatively, a minimal but complete example that errors?

I used this file, with Rebridge 2.3.0:

const Redis = require("redis");
const Rebridge = require("rebridge");

class KnifeBot {
    constructor(config) {
        this.redis = Redis.createClient(config.redisOptions);
        this.db = new Rebridge(this.redis, config.rebridgeOptions);
    }

    pickGame() {
        return "Hey";
    }

    setGame() {
        let game = this.pickGame() // This line errors
        console.log(game);
    }
}

const bot = new KnifeBot({
    redisOptions: {},
    rebridgeOptions: {
        mode: "deasync"
    }
});
bot.setGame();

It works correctly by printing "Hey" to the console. It also works with mode: "promise" and without any Rebridge options.

from rebridge.

Ovyerus avatar Ovyerus commented on June 9, 2024

Both of my options for Redis and Rebridge aren't defined in my current config file, so undefined. Your example works fine for me, I'll create a stripped down version of my current implementation and see if it fails there.

from rebridge.

Ovyerus avatar Ovyerus commented on June 9, 2024

So it turns out that the this.pickGame is not a function error was caused because I was missing a config option, for some stupid reason. However console.log-ing still results in an error that points to Rebridge.

(It also seems that adding the console.log stops the first error from happening. Somehow.)

I've made a repo here which reproduces the errors.

from rebridge.

CapacitorSet avatar CapacitorSet commented on June 9, 2024

Thank you, I'll work on it.

from rebridge.

CapacitorSet avatar CapacitorSet commented on June 9, 2024

Ah, spotted it! That's a problem with your code, that doesn't depend on the usage of Rebridge. Indeed, if you try to remove all usages of Rebridge, you'll see that it still errors.

The problem is on this line (events/ready.js:23):

if (!bot.gameLoop) bot.gameLoop = setInterval(bot.setGame, bot.config.gameInterval);

What happens is that bot.setGame will not be called on the bot object, but on a Timeout object (specifically, the one returned by setInterval). This behaviour is documented here, and can be solved by using setTimeout(bot.setGame.bind(bot), ...) or more elegantly with setTimeout(() => bot.setGame(), ...).

from rebridge.

Ovyerus avatar Ovyerus commented on June 9, 2024

Huh, that's pretty weird behaviour. Thanks a lot for your help anyway! :)

from rebridge.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.