Help with cancelling msgplus timer - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Help with cancelling msgplus timer (/showthread.php?tid=72536)
Help with cancelling msgplus timer by Rizu on 03-11-2007 at 03:23 AM
I've set up some msgplus timers to automatically send voice clips to my contacts, and I want to be able to cancel them by sending a command. This is a portion of the script:
quote: var ChatWnds = new Array();
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
if(Message == "!s"){
ChatWnd.SendMessage("/vc 15");
ChatWnds[ChatWnds.length-1] = ChatWnd;
MsgPlus.AddTimer("Delay1"+[ChatWnds.length-1], 15300);
}
}
function OnEvent_Timer(TimerId){
switch(TimerId.substr(0,6)){
case "Delay1":
ChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay2"+[TimerId.substr], 15300);
break;
case "Delay2":
ChatWnds[TimerId.substr].SendMessage("/vc 15");
}
}
So, how would I be able to properly call the syntax
MsgPlus.CancelTimer("Delay1"+[ChatWnds.length-1], 15300);
by using a message command?
I've tried several things such as else if but they have only rendered the script unusable. I'm completely out of ideas and can't find any help in the documentation.
RE: Help with cancelling msgplus timer by matty on 03-11-2007 at 04:49 AM
MsgPlus.CancelTimer only accepts 1 parameter... The name of the timer to cancel.
RE: Help with cancelling msgplus timer by Rizu on 03-11-2007 at 05:01 AM
So, it would be like this?
MsgPlus.CancelTimer("Delay1"+[ChatWnds.length-1]);
I've used that instead, but it still is not working...
RE: Help with cancelling msgplus timer by Rizu on 03-11-2007 at 05:50 PM
Clearly, I must be doing something wrong with triggering the command with a message, because those syntaxes work fine without the message command.
Here's what I'm trying to do:
quote: var ChatWnds = new Array();
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
if(Message == "!s"){
ChatWnd.SendMessage("/vc 15");
ChatWnds[ChatWnds.length-1] = ChatWnd;
MsgPlus.AddTimer("Delay1"+[ChatWnds.length-1], 15300);
else if(Message == "!q"){
MsgPlus.CancelTimer("Delay1"+[ChatWnds.length-1]);
What's the proper way to trigger this command with a received message?
RE: Help with cancelling msgplus timer by foaly on 03-11-2007 at 06:02 PM
quote: Originally posted by Rizu
code: var ChatWnds = new Array();
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
if(Message == "!s"){
ChatWnd.SendMessage("/vc 15");
ChatWnds[ChatWnds.length-1] = ChatWnd;
MsgPlus.AddTimer("Delay1"+[ChatWnds.length-1], 15300);
else if(Message == "!q"){
MsgPlus.CancelTimer("Delay1"+[ChatWnds.length-1]);
the way you use the array is wrong...
you should call it like:
code: MsgPlus.CancelTimer("Delay1"+ChatWnds.length-1);
should work...
RE: Help with cancelling msgplus timer by Rizu on 03-11-2007 at 06:07 PM
Yes, that does work. But I need a received message to trigger it, just like how "!s" will trigger the array and timer.
RE: Help with cancelling msgplus timer by vikke on 03-11-2007 at 06:19 PM
code: var aChatWnds = new Array();
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
if(Message == "!s"){
ChatWnd.SendMessage("/vc 15");
aChatWnds[aChatWnds.length-1] = ChatWnd;
MsgPlus.AddTimer("Delay1"+[aChatWnds.length-1], 15300);
else if(Message == "!q"){
MsgPlus.CancelTimer("Delay1"+aChatWnds.length-1);
}
}
I've also changed the ChatWnds name to aChatWnds, because MP!L uses that name. That should work, maybe we are handling wrong with the arrays, don't know.. If it does not work, give me the error.
RE: Help with cancelling msgplus timer by Rizu on 03-11-2007 at 06:24 PM
It is still not working. Here's the complete script with your ammendments:
quote: var aChatWnds = new Array();
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
if(Message == "!s"){
ChatWnd.SendMessage("/vc 15");
aChatWnds[aChatWnds.length-1] = ChatWnd;
MsgPlus.AddTimer("Delay1"+[aChatWnds.length-1], 15300);
else if(Message == "!q"){
MsgPlus.CancelTimer("Delay1"+aChatWnds.length-1);
}
}
function OnEvent_Timer(TimerId){
switch(TimerId.substr(0,6)){
case "Delay1":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay2"+[TimerId.substr], 15200);
break;
case "Delay2":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay3"+[TimerId.substr], 15200);
break;
case "Delay3":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay4"+[TimerId.substr], 15200);
break;
case "Delay4":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay5"+[TimerId.substr], 15200);
break;
case "Delay5":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay6"+[TimerId.substr], 15200);
break;
case "Delay6":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay7"+[TimerId.substr], 15200);
break;
case "Delay7":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay8"+[TimerId.substr], 15200);
break;
case "Delay8":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay9"+[TimerId.substr], 15200);
break;
case "Delay9":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay10"+[TimerId.substr], 15200);
break;
case "Delay10":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
break;
}
}
This has only rendered the script unusable. Perhaps I should debug this?
RE: Help with cancelling msgplus timer by foaly on 03-11-2007 at 07:19 PM
you didn't fix the mistake when you create the timer...
code: aChatWnds[aChatWnds.length-1] = ChatWnd;
MsgPlus.AddTimer("Delay1"+aChatWnds.length-1, 15300);
else if(Message == "!q"){
you used the [] again...
RE: Help with cancelling msgplus timer by Rizu on 03-11-2007 at 08:34 PM
I fixed that error, but it is still not working...
quote: var aChatWnds = new Array();
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
if(Message == "!s"){
ChatWnd.SendMessage("/vc 15");
aChatWnds[aChatWnds.length-1] = ChatWnd;
MsgPlus.AddTimer("Delay1"+aChatWnds.length-1, 15300);
else if(Message == "!q"){
MsgPlus.CancelTimer("Delay1"+aChatWnds.length-1);
}
}
function OnEvent_Timer(TimerId){
switch(TimerId.substr(0,6)){
case "Delay1":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay2"+TimerId.substr, 15200);
break;
case "Delay2":
aChatWnds[TimerId.substr].SendMessage("/vc 15");
RE: Help with cancelling msgplus timer by NanaFreak on 03-11-2007 at 08:49 PM
what is coming up in the debugger? we really need that information to be able to help you out
RE: Help with cancelling msgplus timer by Rizu on 03-11-2007 at 09:30 PM
Okay, I ran the debugger with this:
quote: var ChatWnds = new Array();
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind){
if(Message == "!s"){
ChatWnd.SendMessage("/vc 15");
ChatWnds[ChatWnds.length-1] = ChatWnd;
MsgPlus.AddTimer("Delay1"+ChatWnds.length-1, 15300);
else if(Message == "!q"){
MsgPlus.CancelTimer("Delay1"+ChatWnds.length-1);
}
}
function OnEvent_Timer(TimerId){
switch(TimerId.substr(0,6)){
case "Delay1":
ChatWnds[TimerId.substr].SendMessage("/vc 15");
MsgPlus.AddTimer("Delay2"+[TimerId.substr], 15200);
break;
case "Delay2":
ChatWnds[TimerId.substr].SendMessage("/vc 15");
And the debugger displayed:
quote: Script has been stopped
Error: Syntax error.
Line: 7. Code: -2146827286.
Line 7 is else if(Message == "!q"){ in the scripting window.
Next, I removed else from that line, then the debugger displayed:
quote: Error: Expected '}'.
Line: 58. Code: -2146827279.
The actual script is longer, so this line is past the case "Delay 10" call. So I placed an "}" there and it says the script is loaded and ready.
But now, it won't send anything past the first delay, regardless of whether "!q" is sent or not.
RE: Help with cancelling msgplus timer by Ezra on 03-11-2007 at 09:56 PM
That's because you forgot to close the first if statement like the debugger says, you need a }
RE: Help with cancelling msgplus timer by Rizu on 03-11-2007 at 10:02 PM
Now, the script functions, but it does not work the way I want it to. It will just stop the timer after the first delay, regardless of whether "!q" is received or not.
When the script is running properly, I type !s, and the debugger window reads that the function ChatWndReceiveMessage is called, and the voice clip records and sends. After it has been sent, the debugger reads that the Timer has been called as the other voice clip records and so on.
This does not happen when I include the CancelTimer syntax. So, perhaps I'll need to stop the subsequent Timer events from happening.
RE: Help with cancelling msgplus timer by phalanxii on 03-11-2007 at 11:36 PM
code: "Delay1"+ChatWnds.length-1
This is not a valid string. "Delay1" is a string and ChatWnds.length is a number, so the plus operator (+) joins them together as a new string object. The -1 is supposed to subtract 1 from a number object, but as "Delay1"+ChatWnds.length is a string, the result is you get a messed up timer ID.
Your original script was correct in putting brackets there:code: "Delay1"+[ChatWnds.length-1]
This way, the number is calculated first, then appended to "Delay1". The reason why it probably didn't work was because of the end parentheses for the first if statement.
Also, may I suggest naming your timers something like "ClipxChatx". Then a simple regular expression can be used to handle your timers:code: function OnEvent_Timer(TimerId) {
if(/^Clip(\d+)Chat(\d+)$/.test(TimerId)) {
var Clip = RegExp.$1;
var Chat = RegExp.$2;
aChatWnds[Chat].SendMessage("/vc 15");
if(Clip < 10) MsgPlus.AddTimer("Clip" + (Clip * 1 + 1) + "Chat" + Chat, 15200);
}
}
Of course, your method is still valid.
RE: Help with cancelling msgplus timer by foaly on 03-12-2007 at 12:26 PM
quote: Originally posted by phalanxii
code: "Delay1"+ChatWnds.length-1
This is not a valid string. "Delay1" is a string and ChatWnds.length is a number, so the plus operator (+) joins them together as a new string object. The -1 is supposed to subtract 1 from a number object, but as "Delay1"+ChatWnds.length is a string, the result is you get a messed up timer ID.
Your original script was correct in putting brackets there:
code: "Delay1"+[ChatWnds.length-1]
This way, the number is calculated first, then appended to "Delay1". The reason why it probably didn't work was because of the end parentheses for the first if statement.
no... if you want to make sure it is calculated first use:
code: "Delay1"+(ChatWnds.length-1)
but even without it probably works correctly...
RE: RE: Help with cancelling msgplus timer by phalanxii on 03-13-2007 at 08:19 AM
quote: Originally posted by foaly
no... if you want to make sure it is calculated first use:
code: "Delay1"+(ChatWnds.length-1)
but even without it probably works correctly...
The syntax in the original script still works. Take for example:code: var aChatWnds = [1, 2, 3];
Debug.Trace("Delay1"+[aChatWnds.length-1]);
The debug logs "Delay12", as it should be. Sure, your way with round brackets works too.
However, it does not work correctly without it! The same code, without the brackets:code: var aChatWnds = [1, 2, 3];
Debug.Trace("Delay1"+aChatWnds.length-1);
This time, the debug reads "-1.#IND"...
|