quote:
Originally posted by roflmao456
doesnt really work.... but you have a good idea though
when i enter in command it will say COMMAND NOT FOUND
Oops wasn't able to test it I am at work.
code:
/*
made by me, roflmao456 aka john
beta
edited by Matty
*/
var _answer;
var _randomop;
var _random1;
var _random2;
var _on = new Boolean(false);
var _played = new Boolean(false);
var _op = new Array('+', '-', '*', '/');
function OnGetScriptCommands(){
var ScriptCommands = '<ScriptCommands>';
ScriptCommands += '<Command>';
if (_on == false) {
ScriptCommands += '<Name>mgamestart</Name>';
ScriptCommands += '<Description>Starts the Math Game</Description>';
} else {
ScriptCommands += '<Name>mgamestop</Name>';
ScriptCommands += '<Description>Stops the Math Game</Description>';
}
ScriptCommands += '</Command>';
ScriptCommands += '</ScriptCommands>';
return ScriptCommands;
}
function OnEvent_ChatWndSendMessage(pChatWnd, sMessage){
if (_on == false){
if (sMessage.toLowerCase() == '/mgamestart'){
_on = true;
MsgPlus.DisplayToast('Math Game', 'Math Game is now started.');
_playGame(pChatWnd);
return '';
}
} else {
if (sMessage.toLowerCase() == '/mgamestop'){
_on = false;
MsgPlus.DisplayToast('Math Game','Math Game is now stopped.');
_played = false;
return '';
}
}
}
function _playGame(pChatWnd){
Debug.Trace('_playGame function called.'); //start setting random question
_random1 = Math.round(Math.random()*(99)+1);
_random2 = Math.round(Math.random()*(99)+1);
_randomop = Math.round(Math.random()*(_op.length-1));
_answer = eval(_random1+_op[_randomop]+_random2); // set up the answer
if (_played != true){
_on = false;
pChatWnd.SendMessage('Welcome to Math Game, I am going to ask you math questions.');
pChatWnd.SendMessage('What is.. \n\n'+_random1+' '+_op[_randomop]+' '+_random2+'?');
_on = true;
} else {
_on = false;
pChatWnd.SendMessage('new Question!');
pChatWnd.SendMessage('What is.. \n\n'+_random1+' '+_op[_randomop]+' '+_random2+'?');
_on = true;
}
}
function OnEvent_ChatWndReceiveMessage(pChatWnd, sOrigin, sMessage){
if (_on == true){
if (sOrigin != Messenger.MyName){
if (sMessage == _answer){
pChatWnd.SendMessage('That is correct!');
_played = true;
_playGame(pChatWnd);
} else {
pChatWnd.SendMessage('That is wrong. The correct answer was: '+_answer+'.');
_played = true;
_playGame(pChatWnd);
}
}
}
}
that should work, I had _playGame() when it should be _playGame(pChatWnd).