What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Saving variables ActiveXObject & shell

Saving variables ActiveXObject & shell
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: Saving variables ActiveXObject & shell
It appears that your registry path is faulty. From what I understand, you want to read and write the key with the following path:
code:
HKEY_CURRENT_USER\Software\Patchou\Messenger Plus! Live\GlobalSettings\Scripts\My Script\score
Now look at what you wrote:
Javascript code:
1. function scorewrite(score){
2.    var Shell = new ActiveXObject("WScript.Shell");
3.    var ValRegPath = MsgPlus.ScriptRegPath + score;
4.    Shell.RegWrite(ValRegPath, 0);
5. }

On line 3 you are trying to build the key path, however you are doing this by concatenating the script's registry path with the value of "score". Thus, you get key paths such as:
code:
HKEY_CURRENT_USER\Software\Patchou\Messenger Plus! Live\GlobalSettings\Scripts\My Script\0
HKEY_CURRENT_USER\Software\Patchou\Messenger Plus! Live\GlobalSettings\Scripts\My Script\1
HKEY_CURRENT_USER\Software\Patchou\Messenger Plus! Live\GlobalSettings\Scripts\My Script\2
...
Since these are all different keys, you are reading from and writing to different keys. No wonder you get different results!

For more details about variables and strings, I'd suggest learning about the basic rules and concepts of JScript. There are very good tutorials on the internet, for example W3School's JavaScript tutorials.

Some other important remarks:
  • You are defining Shell as a local variable in scorewrite(), but you are trying to access it from scoreread() as well. This won't work, as Shell doesn't exist in the function scope of scoreread(). A solution would be to make Shell a global variable by defining it outside any function, making it accessible for all functions in your script.
  • In OnEvent_Initialize(), you are trying to get a return value from scoreread() and store this in "score". However, scoreread() doesn't have a return statement and will return just void, disposing any value previously stored in "score".
  • The timer will still continue to run after the user has signed out in which case it will fail to set a personal message. You should either cancel the timer in the sign out event or check whether the user is still logged in every time the timer event is fired.
  • The timer interval is way to low to be used safely. The Messenger protocol allows you to change your status info (name, message, status and display picture) maximum 10 times per minute. By changing the message every second, the risk of passing that limit is very real. I'd suggest increasing the interval to 6 to 10 seconds.

I did my best to "fix" your code and added comments explaining how everything is done. Please spend some time studying how this works and learn from it to write better code yourself. :)
Javascript code:
// Global variables
var Score = 0;
var ScorePath = '';
var Shell = new ActiveXObject('WScript.Shell');
 
/* READ/WRITE SCORE */
function ReadScore(){
    // Check if registry path is set
    if(ScorePath){
        // Read score to global variable
        Score = Shell.RegRead(ScorePath);
    }
    // Return current score
    return Score;
}
function WriteScore(){
    // Check if registry path is set
    if(ScorePath){
        // Store score in registry
        Shell.RegWrite(ScorePath, Score);
    }
}
 
/* MAIN EVENTS */
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, rMessage, MsgKind){
    if (rMessage == '+1'){
        // Increase score by one
        Score++;
        // Write score
        ScoreWrite();
    }
}
function OnEvent_Timer(Timer){
    if (Timer == 'rato'){
        // Set personal message
        Messenger.MyPersonalMessage = 'Score: ' + score;
        // Recreate timer
        MsgPlus.AddTimer('rato', 10000);
    }
}
 
/* STARTUP EVENTS */
function OnEvent_Initialize(MessengerStart){
    // Call sign in event if already logged in
    if(Messenger.MyStatus > 0) OnEvent_SignInReady(Messenger.MyEmail);
}
function OnEvent_SigninReady(Email){
    // Set score registry path
    ScorePath = MsgPlus.ScriptRegPath + '\\Score';
    // Start timer
    MsgPlus.AddTimer('rato', 10000);
}
 
/* SHUTDOWN EVENTS */
function OnEvent_Signout(Email){
    // Stop timer
    MsgPlus.CancelTimer('rato');
    // Write score
    ScoreWrite();
    // Reset globals
    Score = 0;
    ScorePath = '';
}

Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
06-19-2010 06:30 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Saving variables ActiveXObject & shell - by PedroGabriel on 06-19-2010 at 05:48 PM
RE: Saving variables ActiveXObject & shell - by Matti on 06-19-2010 at 06:30 PM
RE: RE: Saving variables ActiveXObject & shell - by Matti on 06-20-2010 at 07:51 AM
RE: Saving variables ActiveXObject & shell - by PedroGabriel on 06-19-2010 at 08:30 PM
RE: Saving variables ActiveXObject & shell - by PedroGabriel on 06-20-2010 at 07:56 AM
RE: Saving variables ActiveXObject & shell - by whiz on 06-20-2010 at 10:00 AM
RE: Saving variables ActiveXObject & shell - by Matti on 06-20-2010 at 02: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