Shoutbox

new and need some help - 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: new and need some help (/showthread.php?tid=93275)

new and need some help by debeste95 on 12-21-2009 at 01:02 PM

hey all,
i just downloaded Messenger Plus! and also donwloaded some scripts (me and my friend are addicted to the pokemsn) and now i like to make my own scripts too
i have a little experience with programming such like GML (noob programming language for Game Maker) so i know the basics of coding
now i like to learn some things, so i could make my own scripts.
i like to start with some easy things, and need some help with that
i can't really find good tutorials to start with. i already did the help-file thingy with "starting with scripts" and i understood most of that
but if i want to make a little program, i go stuck...
can some1 just help me with simple things like this:
i wanna make a program that if some1 says something, my pc says: "blablablabla", just for starting with scripts...
but i thought i could make this with this event thingy:

code:
OnEvent_ChatWndReceiveMessage
but i already got stuck...
what do i have to fill in so if just the other person syas anything, my pc says "blablablabla". thanks for reading, i'm waiting for an answer! :)
RE: new and need some help by SmokingCookie on 12-21-2009 at 01:15 PM

Hello debeste95
(Cool name! :P )

Event handlers, as these are called, are just functions with a specific name that Plus! recognises:

JScript code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind) {
    if(Origin !== Messenger.MyName) { // Check if we did not send the message
        MsgPlus.DisplayToast("","A contact has said something!");
        [whatever you want to do]
    }
    return Message; // We don't want to do anything with the Message
}


This will display a pop-up message in the bottom-right corner of the screen, titled "Messenger Plus! Live", saying "A contact has said something!"; no sound will be played when displaying the toast and it won't be clickable.
RE: RE: new and need some help by debeste95 on 12-21-2009 at 01:20 PM

quote:
Originally posted by SmokingCookie
Hello debeste95
(Cool name! :P )

Event handlers, as these are called, are just functions with a specific name that Plus! recognises:

JScript code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind) {
    if(Origin !== Messenger.MyName) { // Check if we did not send the message
        MsgPlus.DisplayToast("","A contact has said something!");
        [whatever you want to do]
    }
    return Message; // We don't want to do anything with the Message
}


This will display a pop-up message in the bottom-right corner of the screen, titled "Messenger Plus! Live", saying "A contact has said something!"; no sound will be played when displaying the toast and it won't be clickable.
so when do i have to put 'if', and when do i have to put 'function' before the event?
çause in GML (it's a noob language, i know) you always use if, so i don't have any experience with function...
but i think this will work, much thanx, now i can try to make my own pokemon battler with uber-pro functiens etc. (kidding! :P)
RE: new and need some help by SmokingCookie on 12-21-2009 at 01:25 PM

You put the "function" keyword in front of the name, simply because it is a function. JScript does support events, but in a very different way. Patchou has programmed Plus! try and to call these functions (if they exist in the JScript code) when the corresponding event occurs:

JScript code:
function HelloWorld() { // define function
    MSgPlus.DisplayToast("","Hello world!");
}
 
Hello world(); // call function


In the above code, a function, named HelloWorld(), is defined (i.e. "tell the scripting engine what the function does"). It displays a toast.

After defining the function, it is called: we tell the scripting engine to actually run the code inside the function: display a toast.

The "if" part checks whether the screen name of the contact who sent the message (the Origin parameter) is not the same as your screen name. In the latter case, the function is called directly upon OnEvent_ChatWndSendMessage(); this is again a function called when a specific action is performed: a message is sent by clicking the "Send" button in a conversation window.

code:
if(1 === 2) {
    MsgPlus.DisplayToast("","One is equal to Two!");
} else {
    MsgPlus.DisplayToast("","One is not equal to Two");
}


In the above code, the second toast is always displayed, as 1 is not the same as 2.
RE: RE: new and need some help by debeste95 on 12-21-2009 at 01:31 PM

quote:
Originally posted by SmokingCookie
You put the "function" keyword in front of the name, simply because it is a function. JScript does support events, but in a very different way. Patchou has programmed Plus! try and to call these functions (if they exist in the JScript code) when the corresponding event occurs:

JScript code:
function HelloWorld() { // define function
    Messenger.DisplayToast("","Hello world!");
}
 
Hello world(); // call function


The "if" part checks whether the screen name of the contact who sent the message (the Origin parameter) is not the same as your screen name. In the latter case, the function is called directly upon OnEvent_ChatWndSendMessage(); this is again a function called when a specific action is performed: a message is sent by clicking the "Send" button in a conversation window.
i think i got it now...
so for every function in that help-file thingy you put 'function' instead of 'if'?
i'm gonna try some little things to learn more about it, thank you guys! :)
RE: new and need some help by SmokingCookie on 12-21-2009 at 01:33 PM

Please note that I've made a mistake in the code, it should be MsgPlus.DisplayToast("","Hello world!");

Indeed, all these event things are just functions ;)

"if" checks whether something is true or not, you'll see more on MSDN (a scripter's best friend):

if...else statement @ MSDN


RE: new and need some help by debeste95 on 12-21-2009 at 01:37 PM

thanx, man!
but now i have a problem... how do i get my script working? if my other scripts are automatically working, but i can't start my script. do i need to make a scriptinfo.xml first?


RE: new and need some help by SmokingCookie on 12-21-2009 at 01:41 PM

View Script management ("Scriptbeheer"), click the "New" button, fill in a name, code your script (be sure to save regularly!) and if you're planning on distributing your script, you must indeed make a ScriptInfo.xml.


RE: new and need some help by debeste95 on 12-21-2009 at 01:47 PM

i already made my script, and i see the script name in that block ("negeerstand") :p
but if i press (omfg what's "toepassen" in english?)  then it says
"the script "negeerstand" can't be started, it got damaged(?) or you don't have permission" (translated from dutch)
all other scripts says: "started", but "negeerstand" doesn't :(


RE: new and need some help by SmokingCookie on 12-21-2009 at 01:50 PM

Toepassen = to apply :P

Anyways, in this case, you need to edit the script; either click the Edit button, or open the script file(s ) in your favourite editor. A "damaged" script means there's a serious error. You might want to check the debugging window for more information on this specific error.


RE: new and need some help by matty on 12-21-2009 at 01:53 PM

It means that you likely have a syntax error. In the Script preferences window click Enable Debugging or Developer Tools or whatever its called at the bottom.

This will open the Script Debugger and will tell you what is wrong with your script.

Alternatively post both the code and the debug window contents and we can help out.


RE: RE: new and need some help by debeste95 on 12-21-2009 at 01:55 PM

quote:
Originally posted by SmokingCookie
Toepassen = to apply :P

Anyways, in this case, you need to edit the script; either click the Edit button, or open the script file(s ) in your favourite editor. A "damaged" script means there's a serious error. You might want to check the debugging window for more information on this specific error.
thanx, i would try that...
and learned another word today! :D great! :P
RE: new and need some help by debeste95 on 12-21-2009 at 04:09 PM

i got rid of the error, and it worked...
but now a question about actions...
i don't really get where i can find the ections in the help file thingy... are object actions? 'cause i wanna make it so if some1 talks, it automatically says: 'blablablabla' so what's the actin codes for automatically saying something? and where can i find the actions?

sorry, next time i will search first...
i got it...
but what's the difference now between functions and properties?
i know what functions are nog, but what are those properties?

and eh... i made a little code, but it doesn't work... how do you use sendmessage?

code:
var naam

function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind) {
    if(Origin !== Messenger.MyName) { // Check if we did not send the message
        SendMessage(Blablablabla);
         naam=name;
         SendMessage("hallo, " + naam + "!");
         
       // [whatever you want to do]
    }
    return Message; // We don't want to do anything with the Message
}
why doesn't he sends a message?

i added ChatWnd. before both sendmessages, he says blablablabla now, but he doesn't say: hallo (name) !

rofl, 5th edit...
now i also added ChatWnd. before name and it worked, but now he says
halle, undefined!
RE: new and need some help by SmokingCookie on 12-21-2009 at 05:49 PM

Because the variable "name" does not exist. I think you mean

JScript code:
naam = Origin;


This'll do.
The sending part: "SendMessage" is not a global function like you are using it. It is a method: a function that belongs to some object. So instead, you need to use this:

JScript code:
var naam;
 
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind) {
    if(Origin !== Messenger.MyName) { // Check if we did not send the message
        //SendMessage(Blablablabla);
         naam = Origin;
         ChatWnd.SendMessage("hallo, " + naam + "!");
    }
    return Message; // We don't want to do anything with the Message
}


Notice any coincidence like OnEvent_ChatWndReceiveMessage's first parameter and the name of the object that has the SendMessage(); method? These must be the same. The function OnEvent_ChatWndReceiveMessage(); takes four "things" called arguments. The first one is an object: the chat window. The second (Origin) is the screen name of the person that sent the message. Message is the fourth, containing the actual message and the last one, MessageKind, tells you what type of message you're dealing with (offline message, search, search result, normal message etc.; see scripting documentation). Note that you can do this as well:

JScript code:
function OnEvent_ChatWndReceiveMessage(a1,a2,a3,a4) /* function header */{
    [some code in the function body]
}


Plus! won't mind that the argument names have been changed. But once you change the argument names in the function header (see above), you need to change it in the function body as well, so:


JScript code:
function OnEvent_ChatWndReceiveMessage(a1 /* originally the ChatWnd argument */,a2 /* Idem, Origin */,a3 /* Idem Message */,a4 /* Idem MessageKind */) /* function header */{
    a1.SendMessage("Hello world!"); // works okay
    ChatWnd.SendMessage("Hello world!"); // An error will occur now, saying that ChatWnd is not defined
}


So if you wish to stick to "naam = name" thingy:

JScript code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,name,Message,MessageKind) {
    [code here]
}


RE: RE: new and need some help by debeste95 on 12-21-2009 at 05:55 PM

quote:
Originally posted by SmokingCookie
Because the variable "name" does not exist. I think you mean

JScript code:
naam = Origin;


This'll do.
The sending part: "SendMessage" is not a global function like you are using it. It is a method: a function that belongs to some object. So instead, you need to use this:

JScript code:
var naam;
 
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind) {
    if(Origin !== Messenger.MyName) { // Check if we did not send the message
        //SendMessage(Blablablabla);
         naam = Origin;
         ChatWnd.SendMessage("hallo, " + naam + "!");
    }
    return Message; // We don't want to do anything with the Message
}


Notice any coincidence like OnEvent_ChatWndReceiveMessage's first parameter and the name of the object that has the SendMessage(); method? These must be the same. The function OnEvent_ChatWndReceiveMessage(); takes four "things" called arguments. The first one is an object: the chat window. The second (Origin) is the screen name of the person that sent the message. Message is the fourth, containing the actual message and the last one, MessageKind, tells you what type of message you're dealing with (offline message, search, search result, normal message etc.; see scripting documentation). Note that you can do this as well:

JScript code:
function OnEvent_ChatWndReceiveMessage(a1,a2,a3,a4) /* function header */{
    [some code in the function body]
}


Plus! won't mind that the argument names have been changed. But once you change the argument names in the function header (see above), you need to change it in the function body as well, so:


JScript code:
function OnEvent_ChatWndReceiveMessage(a1 /* originally the ChatWnd argument */,a2 /* Idem, Origin */,a3 /* Idem Message */,a4 /* Idem MessageKind */) /* function header */{
    a1.SendMessage("Hello world!"); // works okay
    ChatWnd.SendMessage("Hello world!"); // An error will occur now, saying that ChatWnd is not defined
}


So if you wish to stick to "naam = name" thingy:

JScript code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,name,Message,MessageKind) {
    [code here]
}


i want naam to be the name of the person i send to...
i read the helpfile and it says name; returns the other's name...

RE: new and need some help by SmokingCookie on 12-21-2009 at 06:02 PM

That sounds like a Contact object. No Contact object is passed to the OnEvent_ChatWndReceiveMessage(); function. Name is a property of a Contact object. Like a method, a property belongs to a certain object. I'll set an example:

JScript code:
var oContact = Messenger.MyContacts.GetContact("john-doe@live.com"); // Change this Windows Live ID to someone from your contact list!!
 
MsgPlus.DisplayToast("","John-doe@live.com's Windows Live ID: " + oContact.Name);


Oh and on a side note: JScript is case-sensitive. So Name is not the same as name.
RE: new and need some help by debeste95 on 12-22-2009 at 09:40 AM

buut... that's a piece of code to return the email of someone in my list. but how do i get the e-mail og the one i'm talking with?


RE: new and need some help by SmokingCookie on 12-22-2009 at 09:52 AM

You can't do that directly, as there is no "Email" parameter in OnEvent_ChatWndReceiveMessage(); This is where loops come in:

JScript code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind) {
    if(Origin !== Messenger.MyName) {
        for(var e = new Enumerator(ChatWnd.Contacts); !e.atEnd(); e.moveNext()) {
            Debug.Trace(e.item().Email); // Displays the WlID of the current contact
        }
    }
}


This is a for loop. It works like this:
for(Initial variable(s); Testing condition; Increment) {
    Code
}

  • Initial variable(s): this is what you have at the beginning, so an enumerator, array or whatsoever
  • Testing condition: if, and only if the testing condition is true, the Code will be executed
  • Increment: after the code has been executed, the Increment part is executed. If the Testing condition is false, this will not e executed

RE: new and need some help by debeste95 on 12-22-2009 at 09:55 AM

aah, i think i got it! ;)
thanx, man! you really helped me alot- and fast! :)


RE: new and need some help by SmokingCookie on 12-22-2009 at 09:58 AM

You're always welcome, that's what the forums are for ;)


RE: new and need some help by debeste95 on 12-22-2009 at 12:46 PM

well... i guess i have another question :p
i already made something that if somebody says anything, my scripts says: "i'm away, talk to me later" but how do i make it like if he says "hi", my pc says "hello" and if he ask "how are you?" my script automatically says "fine" (just some examples)
so what code do i need to use that he check if what he says is something i programmed? like the pokemsn or battle does with
"-use (attack)" or "-heal"...

debeste95 ;)