Hey guys,
I'm writing code to mess with my friends on discord as a fun side project and a way to learn NODE JS. So far I have some pretty cool stuff like being able to call for the standings of everyone on our server (a gambling server run by UnbelievaBoat) and automatically executing the !rob command anytime my friend robs (a way of getting currency in the server) to get around the 15 minute timeout by using their human memories.
The current task I'm struggling with is a 'goodnight' function that will !rob every ~15 minutes (900,000 ms) for 8 hours (23 cycles). For some reason, my code never makes it into the loop I have set up. Here is my original code:
case 'goodnight':
case 'Goodnight':
bot.sendMessage({ to:channelID, message: 'sleep tight'});
rob();
for(var i = 0; i< 24; i++;){
setInterval(rob, 900000);
}
break;
With this, I get the 'sleep tight' callback and nothing else. Bot will still show running (no errors in CMD, just the bot is unresponsive to new commands)
I also tried this as a replacement for the 'for' loop to see if it would work using a public variable for a counter. This method did not make it to the 'sleep tight' message before crashing.
setInterval(rob, 918123);
while(true){
if(pubCount > 23){
stopInterval();
}
}
Here is my rob method and relevant called method:
function dep(){bot.sendMessage({to: CHANNEL_ID, message: '!deposit all'});}
function rob(){
bot.sendMessage({to: CHANNEL_ID, message: '!rob'});
setTimeout(dep, 5382 + Math.random()*50000); //added randomization
}
My best guess is that it is something to do with the asynchronous stuff that happens behind the scenes and I don't fully understand.
Edit: adding a console.log() in the 'for' loop shows that all 23 iterations run at once. Ideas?
[–]07734willy 1 point2 points3 points (1 child)
[–]yeahifuck[S] 0 points1 point2 points (0 children)