What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Help - I'm new to scripting!

Pages: (2): « First [ 1 ] 2 » Last »
Help - I'm new to scripting!
Author: Message:
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. Huh?  Help - I'm new to scripting!
I've just started working on an "Instant Response" script, that can send a message or a /command after someone says something to you.  But I have a few problems since I am very new to this:

1) I don't know how to make an enable/disable option (for chat windows and the contact list) in the script option menu.
2) I don't know how to make an options screen, to change the delay and message, either!

If anyone can give me the basic code for it, I would really appreciate it.  :D

I have attached the script file in the message below, and as an attachment (in script format - ".js").


jscript code:
var SettingMessage;
var SettingTimer;

function OnEvent_Initialize(MessengerStart)
{
    SettingMessage = "/nudge";
    SettingTimer = 100;
}

function OnEvent_Timer(TimerID)
{
    Debug.Trace("Timer launched");
    Messenger.OpenChat(TimerID).SendMessage(SettingMessage);
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    if (Origin != Messenger.MyName) {
    Debug.Trace("Message received");
    var Contacts = ChatWnd.Contacts;
    var e = new Enumerator(Contacts);
    for(; !e.atEnd(); e.moveNext()) {
        var Contact = e.item();
        Debug.Trace(" " + Contact.Email);
    }
    if (Message != SettingMessage)
    {
    var Contacts = ChatWnd.Contacts;
    var e = new Enumerator(Contacts);
    var NoContacts = 0;
    for(; !e.atEnd(); e.moveNext()) {
        var Contact = e.item();
        Debug.Trace(" " + Contact.Email);
        NoContacts = NoContacts + 1;
    }
    Debug.Trace(NoContacts);
    if (NoContacts == 1) {
        MsgPlus.AddTimer(Contact.Email, SettingTimer);
        Debug.Trace("Timer started");
    }
    }
    }
}
11-15-2008 03:12 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Help - I'm new to scripting!
For the menu option look at something like this
Volv's reply to Tips

As far as creating a Window this is all done in XML. Take a look at some other script and see how they do things and don't forget to check out the official documentation on the site.
11-25-2008 04:31 PM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. RE: Help - I'm new to scripting!
Okay, I get the menu, but how can I use the menu to enable and disable the script?
11-26-2008 08:16 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Help - I'm new to scripting!
Uusing this:
jscript code:
function OnEvent_MenuClicked(sMenuId){
    if(sMenuId=="mnuItem1"){
        ...
    }
}

You can set a boolean variable that will enable or disable the script.

This post was edited on 11-26-2008 at 08:40 PM by matty.
11-26-2008 08:23 PM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. RE: Help - I'm new to scripting!
I get that, but I'm still not sure how to make a boolean variable to enable/disable the script...  (sorry, I'm really new to this).
11-26-2008 09:01 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Help - I'm new to scripting!
Do you want the ability to prevent nudging if the script is "disabled" is that the affect you are trying to achieve?

Also I know you are new but you can cut down on some code for example:

jscript code:
// Create an object to store our sent messages
var mySentMessages = {};
var bEnabled = true;

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
    if (mySendMessages[ChatWnd.Handle] != Message) {
        Debug.Trace("Message received");
        if (Message != '/nudge') {
            if (ChatWnd.Contacts.Count == 1 && bEnabled == true) {
                for (var e = new Enumerator(ChatWnd.Contacts); !e.atEnd(); e.moveNext()) {
                    // store the new chat window in a variable
                    var pChat = Messenger.OpenChat(e.item().Email)
                    // check if the chat window's typing area is enabled and the user isn't blocked
                    if (pChat.EditChangeAllowed == true && e.item().Blocked == false) {
                        pChat.SendMessage('/nudge');
                    }
                }
            }
        }
    }
}

function OnEvent_ChatWndSendMessage(ChatWnd, Message){
    mySentMessages[ChatWnd.Handle] = Message; // store the last sent message in an object
}

function OnEvent_ChatWndDestroyed(ChatWnd) {
    delete mySentMessages[ChatWnd.Handle]; // delete the message from the object as it isn't needed anymore
}

/*

Use bEnabled to control whether or not you want the nudge to be sent.
When the user clicks the menu item to disable the script set bEnabled = false; and vice versa when they are enabling it.

*/
11-27-2008 02:29 PM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. RE: Help - I'm new to scripting!
So, in the "on click" thing for enable and disable in the script menu, I need to put "bEnabled = [true/false]", right?
11-27-2008 07:37 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Help - I'm new to scripting!
quote:
Originally posted by whiz
So, in the "on click" thing for enable and disable in the script menu, I need to put "bEnabled = [true/false]", right?
Yeah exactly. You want to change the variable so that it will disable the script internally.
11-27-2008 07:38 PM
Profile E-Mail PM Find Quote Report
whiz
Senior Member
****


Posts: 568
Reputation: 8
– / – / Flag
Joined: Nov 2008
O.P. RE: Help - I'm new to scripting!
Sorry - another question!

I'm trying this code on a simpler script, that displays toasts to the user regarding certain information, like sign-ins, name changes and so on.

Am I right in thinking that the menu items should be set like this:
jscript code:
function OnEvent_MenuClicked(sMenuId)
{
    if(sMenuId=="Enable")
    {
        var bEnabled = true;
        var Message = "Toaster has just been enabled!";
        Message = MsgPlus.RemoveFormatCodes(Message);
        MsgPlus.DisplayToast("Toaster", Message);
        Debug.Trace("Toaster | Enable");
    }
    if(sMenuId=="Disable")
    {
        var bEnabled = false;
        var Message = "Toaster has just been disabled!";
        Message = MsgPlus.RemoveFormatCodes(Message);
        MsgPlus.DisplayToast("Toaster", Message);
        Debug.Trace("Toaster | Disable");
    }
}

And then each toast should be like this:
jscript code:
function OnEvent_Signin(Email)
{
    if(bEnabled=="true")
    {
        var Message = "You have been signed in.";
        Message = MsgPlus.RemoveFormatCodes(Message);
        MsgPlus.DisplayToast("Toaster", Message);
        Debug.Trace("Toaster | UserSign-in");
    }
}
12-07-2008 11:25 AM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Help - I'm new to scripting!
That'll work, but not in the way you'd expect it. :P Therefore, in your OnEvent_Signin function, use
jscript code:
if(bEnabled)
since the way you do it now is by comparing it to the literal message "true" rather than the boolean value true. :)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
12-07-2008 11:29 AM
Profile E-Mail 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