Shoutbox

Need scripting 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: Need scripting help (/showthread.php?tid=96438)

Need scripting help by Juffle on 01-23-2011 at 09:30 PM

Hi,

I'm trying to write a script that when I log on from my cell phone messenger client that my home PC messenger change my Display Picture to a mobile picture, then wait 10 mins of idle and change it again to another DP then wait 2 mins and change it back to my default one.

So far I've writen this but it dosent work at all... What I'm doing wrong ?

I would really appreciate some help as I'm not used in jscripting.

Thank you

Juffle

-----Code-----

var mobileCode = "(mp)";

function OnEvent_MyNameChange(NewName) {
    if (Messenger.MyName.lastIndexOf(mobileCode)) {
        MsgPlus.AddTimer(on,5000);
    }
}


function OnEvent_Timer(TimerId) {
    if (TimerId == "on") {
        Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\mobile_on.gif";
        MsgPlus.AddTimer(off,600000);
    }
    else if (TimerId == "off") {
        Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\mobile_off.gif";
        MsgPlus.AddTimer(default,120000);
    }
    else if (TimerId == default) {
        Messenger.MyDisplayPicture = MsgPlus.ScriptFilesPath + "\\images\\default.gif";
        Messenger.MyName = Messenger.MyName.replace(mobileCode,"");
    }
}


function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
    if (Origin == Messenger.MyName) {
        if (Messenger.MyName.lastIndexOf(mobileCode)) {
            MsgPlus.CancelTimer(off);
            MsgPlus.CancelTimer(default);
            MsgPlus.AddTimer(on,5000);
        }
    }
}

---End Of Code-----


RE: Need scripting help by CookieRevised on 01-24-2011 at 01:19 AM

For starters:

on, off and default are strings.
And thus there should be quotes around those strings.

You did it twice good in if (TimeId == "on" ) and if (TimeId == "off" ). But all the other occurances of those strings lack the quotes (and thus are threated as undefined variables)....



Another thing you might want to consider: Timers do not stop running after you've signed out!

This means that if you are signed out for some reason, the timers will still keep on running (until they fire). At which time you might not be signed in once again and thus an error will occur when the timer event tries to set your display picture. Similar stuff will happen when you sign out and someone else  (or you with another identity) signs in after that; the timers might still be running and the other person's display picture will be set instead....

To solve this _extremely common_ mistake, simply cancel all the used timers in a OnEvent_SignOut event.

;)


RE: Need scripting help by Juffle on 01-24-2011 at 01:33 AM

Thank you for pointing that out, but I've noticed that the "OnEvent_MyNameChange" dosent get triggered when the name change occur from another client changing the name even if the name actualy change. So this make my idea useless.


RE: Need scripting help by CookieRevised on 01-24-2011 at 01:44 AM

quote:
Originally posted by Juffle
Thank you for pointing that out, but I've noticed that the "OnEvent_MyNameChange" dosent get triggered when the name change occur from another client changing the name even if the name actualy change. So this make my idea useless.
it doesn't? but the display picture does change? hmmm .... didn't knew that (never tried something like that before with MPOP either).

btw, make sure you actually do change the name on your mobile after you signed in on your mobile phone. Thus, first sign in, then change the name. A name change event wont fire when you sign in with another name than before. The code must actually 'see' the name change happening live so to speak.

Another way would be to send a remote command and check upon that in the OnEvent_ChatWndReceiveMessage event... like !Mobile or something.. Actually, I dunno if it needs to be a remote command, since stuff said on your mobile phone is normally mimiced on your PC because of the MPOP feature. So, it might be that a normal command would do fine.

Again, I never tried something like this so I dunno exactly how everything will behave in those circumstances (and I can't test at this moment either), so you'll have to do some tests yourself.... or wait for someone who has tried it before.

Either way... appart from those small (but nevertheless crucial) mistakes of forgetting the quotes around those strings, I think you have the hang of it and seem to have the proper knowhow to pull this of on your own in a good manner though.....

;)
RE: Need scripting help by Spunky on 01-24-2011 at 12:31 PM

quote:
Originally posted by Juffle
I've noticed that the "OnEvent_MyNameChange" dosent get triggered when the name change occur from another client changing the name even if the name actualy change

Just to clarify, which version of WLM are you using and does the event fire when you change your name on the local machine?