Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: undefined is not a function #3

Open
Ezcha opened this issue Nov 29, 2015 · 0 comments
Open

Uncaught TypeError: undefined is not a function #3

Ezcha opened this issue Nov 29, 2015 · 0 comments

Comments

@Ezcha
Copy link

Ezcha commented Nov 29, 2015

I am trying to make a mining plugin for my bot. However, when I send it the mine command, it freezes and gets the error "Uncaught TypeError: undefined is not a function" on line 222 in index.js

Here is my code:

var mineflayer = require('mineflayer');
var scaffoldPlugin = require('mineflayer-scaffold')(mineflayer);
var blockFinderPlugin = require('mineflayer-blockfinder')(mineflayer);
var vec3 = mineflayer.vec3;
module.exports.inject = inject;

function inject(bot) {

var doMine = false;
var findIds = [16, 15, 14, 21, 56, 73, 74, 129];

////Functions
function findPath() {
    bot.findBlock({
        point: bot.entity.position,
        matching: findIds,
        maxDistance: 64,
        count: 1,
    }, function(err, blockPoints) {
        if (err) {
            fakeConsole("Error looking for blocks.", "error")
        }
        if (blockPoints.length) {
            bot.scaffold.to(blockPoints[0], function(err) {
                if (err) {
                    doMine = false
                    fakeConsole("Didn't get to the ore.", "error");
                } else {
                    if (doMine === true) {
                        findPath();
                    } else {
                        fakeConsole("Ended mining task.", "info");
                    }
                }
            });
        } else {
            doMine = false
            fakeConsole("No ores in range.", "info");
        }
    });
}

////Commands
bot.on('whisper', function(username, message) {
    if (message == "mine start") {
        if (doMine === false) {
            doMine = true;
            fakeConsole("Started mining.", "info");
            findPath();
        } else {
            fakeConsole("I am already mining!", "error");
        }
    }
    if (message == "mine stop") {
        if (doMine === true) {
            doMine = false;
            fakeConsole("Ending mining task...", "info");
        } else {
            fakeConsole("I am not mining.", "error");
        }
    }
});

//Fake console
function fakeConsole(text,type) {
    document = doc = window.document 
    var text = arguments[0];
    var type = arguments[1];
    var para = document.createElement("P");
    var t = document.createTextNode(text);
    para.className = type;
    para.appendChild(t);
    document.getElementById('Space').appendChild(para);
    window.scrollTo(0,document.body.scrollHeight);
    }
fakeConsole("Started mine plugin.", "info")

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant