Shoutbox

Script Always Stopped - 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: Script Always Stopped (/showthread.php?tid=92098)

Script Always Stopped by Samo502 on 09-03-2009 at 03:34 PM

No matter what i do to a(seemingly) simple script i'm trying as my first script it never runs! I've changed it based on every syntax error I can think of but it still won't run.

code:
function OnEvent_MyPsmChange(NewPsm)
{
    var psm = Messenger.MyPersonalMessage();
    ChatWnd.SendMessage("I changed my personal message to: " + psm);
}

RE: Script Always Stopped by matty on 09-03-2009 at 03:46 PM

Well firstly the script is wrong. ChatWnd isn't defined anywhere. However that doesn't explain why the script is stopped. If you import someone elses script does it work?


RE: Script Always Stopped by Samo502 on 09-03-2009 at 03:50 PM

Other scripts work fine, and how is ChatWnd not defined its in the MsgPlus scripting documentation with a list of commands under it?


RE: Script Always Stopped by matty on 09-03-2009 at 04:03 PM

quote:
Originally posted by Samo502
Other scripts work fine, and how is ChatWnd not defined its in the MsgPlus scripting documentation with a list of commands under it?
The ChatWnd object is inherited by certain actions you cannot just use it like that.

You get access to the object by doing something like this for instance:
Javascript code:
var ChatWnd = Messenger.OpenChat ( 'johndoe@hotmail.com');
ChatWnd.SendMessage ( 'This is some text I am sending' );


You can also enumerate any open conversation windows as well:
Javascript code:
 for ( var ChatWnd = new Enumerator ( Messenger.CurrentChats ); !ChatWnd.atEnd ( ); ChatWnd.moveNext ( ) ) {
    ChatWnd.item( ).SendMessage ( 'This is some text I am sending' );
}


Make sense?
RE: RE: Script Always Stopped by Samo502 on 09-03-2009 at 04:12 PM

Javascript code:
var ChatWnd = Messenger.OpenChat ( 'johndoe@hotmail.com');

Coming from someone who knows a few different programming languages, I have never seen an object declared that way, or anything for that matter.  I've only seen that method used to create a simpler way to type a long reference like
code:
variabletypehere NewName = system.bleh.blah.lol();

RE: Script Always Stopped by Matti on 09-03-2009 at 04:37 PM

Since this seems to be a frequently asked question, I'll spend some time explaining this a bit more in depth...

When working with objects, you have to understand the difference between classes (or instances) and singletons (static objects).

  • Class instances are objects which represent an instance of something to communicate with it through its properties and methods.

    The reason why you can't use ChatWnd.SendMessage directly is because SendMessage() needs to communicate with a certain window, but none was specified. You first need to retrieve an instance in some way before working with it. For example, you can get a ChatWnd instance by calling Messenger.OpenChat, but you can also get one by looping through the Messenger.CurrentChats collection or through the ChatWnd parameter of an event. Once you got an instance, you're ready to go.

    Examples: ChatWnd, PlusWnd, Contact, Emoticon, DataBloc,...

  • Singletons are objects that are global (accessible from everywhere in the script) and provide methods and properties without being assigned to one instance. There is only one instance of these objects and you can't create new instances of them.

    The Messenger object for example has a MyName property which always represents the current user's nickname. It doesn't need to know what instance to communicate with, since it's always the same: the name of the currently logged in user (unless the current user is not signed in, but then there's nothing to work with).

    Examples: Debug, Messenger, MsgPlus and Interop.
Hopefully that was helpful. :)
RE: Script Always Stopped by Samo502 on 09-03-2009 at 04:54 PM

That does make a bit more sense because the thought did come to mind as to how it detects which window to send to, as for it being stopped I don't know. However I did get it running shortly after posting as I forgot to mention.


RE: Script Always Stopped by Matti on 09-03-2009 at 05:01 PM

Good thing you figured that out yourself, that really is the best way of learning programming! :)


RE: Script Always Stopped by Samo502 on 09-03-2009 at 05:34 PM

Indeed it is, I based a script to send a custom announcement to my friends as they come online, now to learn XML and how to implement it.... (I'll spend some time with MsgPlus script before doing it though)