What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » adding a counter to my script.

adding a counter to my script.
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: adding a counter to my script.
code:
var RaadselId = Array();
var teller = 0;

function OnEvent_Initialize(bMessengerStart) {
    try {
        var uId = Messenger.MyUserId;
        var Wsh = new ActiveXObject("WScript.Shell");
        teller = parseInt(Wsh.RegRead(MsgPlus.ScriptRegPath + uId + "\\teller"));
    } catch(err) {
        teller = 0;
    }
}

function OnEvent_Signin(Email) {
    OnEvent_Initialize(false);
}


function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind)
{
    var Message=Message.toLowerCase();
    if(MessageKind == 1 && Message.substr(1,4) == "druk")
    {
        var ranNum = Math.floor(Math.random() * Raadsel.length);
        RaadselId[ChatWnd.handle] = ranNum;
        ChatWnd.SendMessage(Raadsel[ranNum]);
        teller++;
        var Wsh = new ActiveXObject("WScript.Shell");
        Wsh.RegWrite(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\teller", teller);

    }

    if(MessageKind == 1 && Message.substr(0,7) == "ik wens" || Message.substr(0,8) == "antwoord" || Message.substr(1,9) == "antwoord")
    {
        ChatWnd.SendMessage(Antwoord[RaadselId[ChatWnd.handle]]);
    }
}
Explanation:
I made use of the Windows registry functions to save and load the counter value. The function OnEvent_Initialize will try to load the value from the registry using the Windows Scripting ActiveXObject called Shell. It first sets the uId to Messenger.MyUserId, so if the user isn't signed in, it'll skip the block and goes to the catch block, which sets the counter to zero.

The same thing will happen when the user signs in, and instead of repating the code, I made a call to the already existing OnEvent_Ititialize function.

When the counter value is increased, the script will write the new value into the registry. This value will then be loaded the next time the script is started. ;)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
08-17-2006 03:38 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
adding a counter to my script. - by laurenz on 08-17-2006 at 03:22 PM
RE: adding a counter to my script. - by Matti on 08-17-2006 at 03:38 PM
RE: adding a counter to my script. - by laurenz on 08-17-2006 at 03:48 PM
RE: adding a counter to my script. - by Ezra on 08-17-2006 at 05:07 PM


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