从另一个文件修改变量

时间:2018-12-06 20:13:38

标签: node.js require var

我已将其保存在名为voting_Request.js的文件中:

else
        {
            count1 = 0;
            count2 = 0;
            boolCheck = true;
            module.exports.count1 = count1;
            module.exports.count2 = count2;
        }

我在名为vote.js的文件中也有此内容:

var request = require('./voting_Request.js');
async run(message,args){
    var c1 = request.count1;
    var c2 = request.count2;
    if(!request.boolCheck){
        message.reply('No ongoing votings please try again when a voting is available');
    }
    else{
        if(request.voted.indexOf(message.author.tag) > -1){
            message.reply("You have already voted!");
        }
        else{
            request.noVote = false;
            switch (args) {
                case '1':
                    c1++;
                    message.reply('Thanks for voting!');
                    request.voted.push(message.author.tag);
                    break;
                case '2':
                    c2++;
                    message.reply('Thanks for voting!');
                    request.voted.push(message.author.tag);
                    break;
                default:
                    message.reply(args + ' is not an available option');
            }
            module.exports.c1 = c1;
            module.exports.c2 = c2;
        }
    }
}

基本上不是从请求文件中获取count1和count2的值,而是仅将其复制到表决.js中的新变量中,而是要从表决.js中修改它们,但是count1和count2中的值将根据表决而改变.js。

感谢您的帮助!

0 个答案:

没有答案