Currently, I am working on a project involving the Kik API to create a bot. The main goal is for the game to initiate when users type "!hangman". A boolean value called hangman activates this process and then becomes inactive. Players can then input "!hangman LETTER" to make guesses. It seems straightforward enough. However, there is an unusual glitch that occurs. The first time someone uses "!hangman", everything works correctly. But the second time, the code crashes, citing that "status" and "incorrectletters" are undefined variables, despite being defined earlier in the code. Any assistance or suggestions would be greatly appreciated!
var hangmanIsActive = false;
var hangmanBootup = true;
bot.onTextMessage((message) => {
if (message.body.startsWith("!help")) {
message.reply("I know the following commands:\n- !Hangman");
}
if (message.body.startsWith("!hangman")) {
if (hangmanBootup == true){
hangmanBootup = false;
message.reply("Welcome to hangman!");
var triesleft = "Tries left: "
var inttriesleft = 10
var alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
"t", "u", "v", "w", "x", "y", "z"];
var stage0 = triesleft + inttriesleft;
var stage1 = "\n"
"\n"
"\n"
" " + triesleft + {} + "\n"
"\n"
"\n"
"\n"
"_|___ \n";
var stage2 = "\n"
" |\n"
" |\n"
" | " + triesleft + {} + "\n"
" |\n"
" | \n"
" |\n"
"_|___ \n";
//remaining stages omitted for brevity...
var words = ["testword"];
var keyword = "testword";
var currentstage = stage0;
var status = keyword.replace(/a/g, "-").replace(/b/g, "-").replace(/c/g, "-").replace(/d/g, "-").replace(/e/g, "-")
.replace(/f/g, "-").replace(/g/g, "-").replace(/h/g, "-").replace(/i/g, "-").replace(/j/g, "-")
.replace(/k/g, "-").replace(/l/g, "-").replace(/m/g, "-").replace(/n/g, "-").replace(/o/g, "-")
.replace(/p/g, "-").replace(/q/g, "-").replace(/r/g, "-").replace(/s/g, "-").replace(/t/g, "-")
.replace(/u/g, "-").replace(/v/g, "-").replace(/w/g, "-").replace(/x/g, "-").replace(/y/g, "-").replace(/z/g, "-");
var inttriesleft = 10
var incorrectletters = []
};
message.reply("Word: " + status + "\nIncorrect letters: " + incorrectletters);
message.reply(currentstage);
if (message.body.split(" ").length != 2){
message.reply("To suggest a letter, use \"!hangman a\" for example.");
return;
}
// remaining logic and conditions omitted for brevity...
};
});