好的,因此我大大减少了代码,现在略有不同,但是它做的是相同的。

game-socket.js


//Start Fight Action
socket.on("fight", () => {
 combat(io, socket, app);
});


action-timer.js


const combat = require("./combat/combat");
module.exports = (type, io, socket, app) => {
  if (type == "combat") {
    app.online.actionTime = setTimeout(() => {
      combat(io, socket, app);
    }, 1000);
  } else if (type == "tradeskill") {
  }
};


fighting.js


const startAction = require("../action-timer");
module.exports = (io, socket, app) => {
  //Run another combat
  console.log("COMBAT");
  startAction("combat", io, socket, app);
};


错误:

action-timer.js:5
      combat(io, socket, app);
      ^

TypeError: combat is not a function
    at Timeout.app.online.actionTime.setTimeout [as _onTimeout] (C:\Users\wjpop\Desktop\kog\funcs\action-timer.js:5:7)
    at listOnTimeout (timers.js:327:15)
    at processTimers (timers.js:271:5)

最佳答案

我想通了,很奇怪,我必须这样做,因为通常不需要这样做,但是action-timer.js应该像这样:

module.exports = (type, io, socket, app) => {
  const combat = require("./combat/combat");
  if (type == "combat") {
    app.online.actionTime = setTimeout(() => {
      combat(io, socket, app);
    }, 1000);
  } else if (type == "tradeskill") {
  }
};

关于javascript - 为什么我的功能无法被识别?的JavaScript,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56680253/

10-12 13:49