Script Always Stopped |
Author: |
Message: |
Samo502
New Member
Posts: 9
Joined: Sep 2009
|
O.P. Script Always Stopped
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);
}
|
|
09-03-2009 03:34 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: Script Always Stopped
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?
|
|
09-03-2009 03:46 PM |
|
|
Samo502
New Member
Posts: 9
Joined: Sep 2009
|
O.P. RE: Script Always Stopped
Other scripts work fine, and how is ChatWnd not defined its in the MsgPlus scripting documentation with a list of commands under it?
|
|
09-03-2009 03:50 PM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: Script Always Stopped
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:
js 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:
js code: for ( var ChatWnd = new Enumerator ( Messenger.CurrentChats ); !ChatWnd.atEnd ( ); ChatWnd.moveNext ( ) ) {
ChatWnd.item( ).SendMessage ( 'This is some text I am sending' );
}
Make sense?
This post was edited on 09-03-2009 at 04:04 PM by matty.
|
|
09-03-2009 04:03 PM |
|
|
Samo502
New Member
Posts: 9
Joined: Sep 2009
|
O.P. RE: RE: Script Always Stopped
js 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();
|
|
09-03-2009 04:12 PM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: Script Always Stopped
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.
|
|
09-03-2009 04:37 PM |
|
|
Samo502
New Member
Posts: 9
Joined: Sep 2009
|
O.P. RE: Script Always Stopped
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.
This post was edited on 09-03-2009 at 04:55 PM by Samo502.
|
|
09-03-2009 04:54 PM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
RE: Script Always Stopped
Good thing you figured that out yourself, that really is the best way of learning programming!
|
|
09-03-2009 05:01 PM |
|
|
Samo502
New Member
Posts: 9
Joined: Sep 2009
|
O.P. RE: Script Always Stopped
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)
|
|
09-03-2009 05:34 PM |
|
|
|