0

So I have this function which was working fine yesterday but today when I turned PC on it stopped working. Were there any updates that I am not aware of, did i maybe accidentally delete something, but I haven't touched code since yesterday? Can someone help me find this annoying bug?

Function I'm trying to reach is inside other folder and other script.

Here is the function:

var npcSchema = new mongoose.Schema({
    NPCname: {type: String, unique:true},
    life: Number,
    zone : String,
    pos_x: Number,
    pos_y: Number,
    zgodba: Boolean
});

npcSchema.NarediNpc = function(imeNpc, socket){
    NPC.findOne({NPCname: imeNpc}, function(err, npc){
        socket.write(packet.build([
            "NPC",
            npc.NPCname,
            npc.life,
            npc.zone,
            npc.pos_x,
            npc.pos_y
        ]));
    })
};

module.exports = NPC = gamedb.model('npcs', npcSchema);

And this is the code where I'm trying to access the function:

var npcNaredi = new require('./Models/user.js');
case "NPC":              
    npcNaredi.NarediNpc("obj_npcLograk", c.socket);
    break;

Variables and function names are written in slovene, I hope that won't make problems, it might actually be just some stupid typo but I can't find it and I'm getting headache from this...

2
  • I see you have a typo with 'socket' and 'soccket'. Could that be your issue? Commented Jan 14, 2017 at 15:10
  • that wasn't there before the guy who edited post accidentaly typed it wrong Commented Jan 14, 2017 at 15:14

1 Answer 1

1

I see that you are trying to create an instance method, try this:

npcSchema.methods.NarediNpc = function(imeNpc, socket){
  // ...
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.