{ combat(i-6ren">
gpt4 book ai didi

javascript - 为什么我的函数不被识别? JavaScript

转载 作者:行者123 更新时间:2023-12-02 23:27:22 24 4
gpt4 key购买 nike

好的,所以我已经大大减少了代码,现在有点不同,但它做了同样的事情。

游戏套接字.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") {
}
};

combat.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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com