0

I am making a Kahoot Bot and I want it to have a feature where I can have the user to choose an answer. I am using readline to grab user input (example code of what I am doing):

var rl = require("readline").createInterface({
      input: process.stdin,
      output: process.stdout
});

rl.question('Type in your answer!\n', (answer) => {
     console.log(answer)
})

but each player (bot) is separated and is not like in 1 cluster. (Cluster as in each bot has the same mind as another one, a.k.a it doesn't spam my console.) I've tried using emitters but I have no idea how to use EventEmitter so I stopped using them. So if I try to do the above code (with 100+ bots), I end up getting my whole console spammed with duplicate characters and lines. How can I hide this?

lemons
  • 1
  • 4
  • 1
    What do mean by a cluster? And which part of the code is being duplicated? The callback where you are logging the answer? Why not simply extract it into a seperate function? – Yousuf Khan Apr 10 '20 at 06:12
  • What I mean by a cluster is like each bot has the same mind as another one. So if it's not a cluster, it would spam my console but if it was a cluster it wouldn't spam my console. I've tried using emitters before but I don't know how to set it up. Sorry if it isn't clear its my first time. – lemons Apr 10 '20 at 06:14
  • okay i think the issue is that you want to ask only `one` question at a given time even though you have multiple users, that right? – Yousuf Khan Apr 10 '20 at 06:17
  • Correct, that is what I was going for. – lemons Apr 10 '20 at 06:18
  • Okay maybe it was just me but I think the question can still be reworded. – Yousuf Khan Apr 10 '20 at 06:22
  • Yeah I agree, i was very unclear. – lemons Apr 10 '20 at 06:23
  • As for the solution, I believe you want a synchronous version of readline where the programs waits for user input before moving to next line of code. – Yousuf Khan Apr 10 '20 at 06:23
  • Ah, so like readline-sync? But how would that stop all the spam though? It would still run all the multiple lines but after each question – lemons Apr 10 '20 at 06:25
  • yes well if your bot is going to ask questions, they'll be printed in the console. Or you'll have to find some other way of asking the questions – Yousuf Khan Apr 10 '20 at 06:26
  • Okay thank you for telling me. – lemons Apr 10 '20 at 06:27

1 Answers1

0

Figured it out, made a variable and a if statement so if 1 bot does it (since the bots are delayed) the variable turns true and so if another bot does it, it goes to a else statement instead.

lemons
  • 1
  • 4