What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » AddTimer makes msn crash

Pages: (2): « First [ 1 ] 2 » Last »
AddTimer makes msn crash
Author: Message:
Dauntless
Junior Member
**


Posts: 16
– / Male / –
Joined: Aug 2006
O.P. AddTimer makes msn crash
Hi,

What I'm trying to do, is this:

[you type] /countdown
[send msg]5
[send msg]4
[send msg]3
[send msg]2
[send msg]1
[send msg]"Happy Newyear"

This is what I have so far:
code:
var counter = 6;
var currentCW;
var counting = false;

function OnEvent_Initialize(MessengerStart)
{
    Debug.trace(" ");
    Debug.trace("------------------ My Script initialised ------------------");
    Debug.trace(" ");
}

function OnEvent_Uninitialize(MessengerExit)
{
}

function OnEvent_ChatWndSendMessage(chatWnd, msg)
{
    if(counting)
    {
        return "";
    }
    var isCommand = checkCommand(msg);
    if(isCommand)
    {
        var command = getCommand(msg);
        switch (command)
        {           
            case "countdown":
                counting = true;
                countDown(chatWnd);
                return "";
                break;
               
            default:
                break;
        }
    }
    else
    {
        return msg;
    }
}

function countDown(chatWnd)
{
    currentCW = chatWnd;
    MsgPlus.AddTimer("commandCountDown", 500);
}

function onEvent_Timer()
{
    counter --;
    Debug.trace("counter = "+counter);
    if(counter == 0)
    {
        counting = false;
        sendMessage("Happy New Year!");
    }
    else
    {
        Debug.trace("Else");
        sendMessage(counter);
    }
}

function sendMessage(msg)
{
    currentCW.sendMessage(msg)
}

function getCommand(msg)
{
    var msgArray = msg.split(" ");
    var command = msgArray[0].substr(1);
    return command;
}

function checkCommand(msg)
{
    if(msg.charAt(0) == "/")
    {
        if(msg.charAt(1) == "/")
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    else
    {
        return false;
    }

}
(I know this code could be A LOT shorter, but i'm trying to do it as well-structured as possible).

I think the problem is that every time a message is sent, the OnEvent_ChatWndSendMessage is called (so not just, when I type something, but also when msn sends out a message (window.sendMessage();).

I thought this would be fixed by the 'counting' var but appearantly, it is not.
I also created an extra variable 'currentCW' because I didn't know how to keep track of the current window, while going from AddTimer to onEvent_Timer


And lastly: Does type-casting exist in JScript?
'cause now, i have this:
sendMessage(counter);

but sendMessage requires a string, not a number. Is it automaticly being casted? (And is there a way to do it manually ?)

All help is welcome :).
08-10-2006 12:08 AM
Profile E-Mail PM Web Find Quote Report
Silentdragon
Full Member
***

Avatar
if(life==null && wrists) EmoAlert();

Posts: 148
Reputation: 2
34 / Male / –
Joined: Jun 2006
RE: AddTimer makes msn crash
1. Jscript automatically converts between types.
2. Stuff:
code:
if(counting)
{
return "";
}
That returns nothing making your script not work. Return msg.

code:
MsgPlus.AddTimer("commandCountDown", 1000);
One second timer.

code:
else
{
Debug.trace("Else");
sendMessage(counter);
Add
code:
MsgPlus.AddTimer("commandCountDown", 1000);
Timers run once then go away, you need to make it run each time you need it to.

And yes it could be greatly simplified.
1278 / 479

This post was edited on 08-10-2006 at 12:46 AM by Silentdragon.
08-10-2006 12:36 AM
Profile E-Mail PM Web Find Quote Report
Dauntless
Junior Member
**


Posts: 16
– / Male / –
Joined: Aug 2006
O.P. RE: RE: AddTimer makes msn crash
quote:
Originally posted by Silentdragon
code:
if(counting)
{
return "";
}
That returns nothing making your script not work. Return msg.

If I would return msg, you would see "/countdown"... And I dont want it to display the command!

quote:
code:
MsgPlus.AddTimer("commandCountDown", 1000);
One second timer.

code:
else
{
Debug.trace("Else");
sendMessage(counter);
Add
code:
MsgPlus.AddTimer("commandCountDown", 1000);
Timers run once then go away, you need to make it run each time you need it to.
I fixed this and now he does display 'Happy new year' after 5 seconds... But I also want him to display '5', '4', '3', ...

And do you know the answer to my other questions ?
08-10-2006 12:49 AM
Profile E-Mail PM Web Find Quote Report
cloudhunter
Senior Member
****


Posts: 536
Reputation: 18
37 / – / –
Joined: Dec 2005
RE: AddTimer makes msn crash
Your code looks needlessly complex, and the fact that OnEvent_ChatWndSendMessage is called evertime a message is sent isn't a problem... And your check command function isn't really needed either. you could just do a simple

code:
if (message == "!countdown") {
countDown();
}

I would tell you more but your code confuses me...

Cloudy
[Image: cloudy.jpg]
Sig by pirateok/marisaok/marisa ;)
quote:
Originally posted by Moulin Rouge
The greatest thing you'll ever learn, is just to love and be loved in return

6914 days, 3 hours, 19 minutes, 33 seconds ago
08-10-2006 01:09 AM
Profile E-Mail PM Find Quote Report
Silentdragon
Full Member
***

Avatar
if(life==null && wrists) EmoAlert();

Posts: 148
Reputation: 2
34 / Male / –
Joined: Jun 2006
RE: AddTimer makes msn crash
quote:
Originally posted by Dauntless
quote:
Originally posted by Silentdragon
code:
if(counting)
{
return "";

}

That returns nothing making your script not work. Return msg.

If I would return msg, you would see "/countdown"... And I dont want it to display the command!

If you read your code you'd understand that because you don't do that, it causes your whole code to fail. Also doing that won't make the command show, as it returns the message if it is counting.

code:
var counter = 6;
var curWnd;

function OnEvent_ChatWndSendMessage(chatWnd, msg)
{
    if(msg == "/countdown") {
        curWnd = chatWnd;
        MsgPlus.AddTimer("commandCountDown", 1000);
        return "";
    }
}

function onEvent_Timer()
{
    counter--;
    Debug.trace("counter = "+counter);
    if(counter == 0)
        curWnd.sendMessage("Happy New Year!");
    else
    {
        curWnd.sendMessage(counter);
        MsgPlus.AddTimer("commandCountDown", 1000);
    }
}
Works, and is simplified.

This post was edited on 08-10-2006 at 05:36 AM by Silentdragon.
08-10-2006 03:17 AM
Profile E-Mail PM Web Find Quote Report
Dauntless
Junior Member
**


Posts: 16
– / Male / –
Joined: Aug 2006
O.P. RE: RE: AddTimer makes msn crash
quote:
If you read your code you'd understand that because you don't do that, it causes your whole code to fail. Also doing that won't make the command show, as it returns the message if it is counting.
I wrote this myself! I just only thought about the first time the event is triggerd (when you type /countdown).

Now, it's really not that complex... I mean, how complex can 100 lines of basic JScript be...

The flow of the program:
-receive message
-check if its a command (checkCommand())
-if its a command, what command? (getCommand())
-switch between the known commands (switch statement)
-if the command is 'countdown', call 'countDown()'
-add a timer and send a message (sendMessage)

Since JScript doesnt support propper OO, I can't put this in nice, structured classes ;).

And from your code, i take it that type conversion is done automaticly ?
08-10-2006 07:45 AM
Profile E-Mail PM Web Find Quote Report
Silentdragon
Full Member
***

Avatar
if(life==null && wrists) EmoAlert();

Posts: 148
Reputation: 2
34 / Male / –
Joined: Jun 2006
RE: AddTimer makes msn crash
Yes, it converts automatically. Although adding strings to integers and such is somewhat weird, but its understandable.

The bottom has more info.
http://pages-perso.esil.univ-mrs.fr/~tourai/JavaScript/ms/5.htm

This post was edited on 08-10-2006 at 07:54 AM by Silentdragon.
08-10-2006 07:51 AM
Profile E-Mail PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: AddTimer makes msn crash
quote:
Originally posted by Dauntless
Now, it's really not that complex... I mean, how complex can 100 lines of basic JScript be
Certainly more complex than 24. If two pieces of code do the same thing, and one is shorter, use that one. Shorter is often simpler.
quote:
Originally posted by Dauntless
Since JScript doesnt support propper OO, I can't put this in nice, structured classes
The only thing that JScript doesn't support is inheritance, which also removes polymorphism and abstraction. Both of which aren't necessary in scripting really.
There are plenty of other OO features though: a function declaration can actually define a class, and using the 'prototype' property, objects both built-in and custom can be extended.
quote:
Originally posted by Dauntless
And from your code, i take it that type conversion is done automaticly ?
JScript is a weakly-typed language, which means that all datatypes are implicit, and all possible conversions are performed automatically.
[Image: spartaafk.png]
08-10-2006 08:43 AM
Profile PM Web Find Quote Report
Dauntless
Junior Member
**


Posts: 16
– / Male / –
Joined: Aug 2006
O.P. RE: RE: AddTimer makes msn crash
quote:
The only thing that JScript doesn't support is inheritance, which also removes polymorphism and abstraction. Both of which aren't necessary in scripting really.
There are plenty of other OO features though: a function declaration can actually define a class, and using the 'prototype' property, objects both built-in and custom can be extended.
Hmm, I hate that kind of OO... I don't know if you know ActionScript, but it's a lot like JScript. v1.0 supports OO through prototypes and V2.0 supports true OO through custom made classes.
08-10-2006 08:49 AM
Profile E-Mail PM Web Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: AddTimer makes msn crash
you can typecast stuff with
code:
var xxx = 1;
var yyy = new String(xxx);
Debug.Trace( typeof(yyy));


code:
var xxx = "1";
var yyy = parseInt(xxx);
Debug.Trace(typeof(yyy));



there are others like Boolean and RegExp
[Image: dt2.0v2.png]      Happy Birthday, WDZ
08-10-2006 08:56 AM
Profile PM Web Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On