What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Timeout Objects

Timeout Objects
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Timeout Objects
If you really want setTimeout functionality, you could try this class I made for my scripts. You have to note though that you can't use "normal" MsgPlus.AddTimer() calls unless you edit the OnEvent_Timer in this class.

Example usage:
js code:
function somefunction(message) {
    Debug.Trace("Timer reached, message received: "+message);
}

var myTimer = new Timer(1000, somefunction, "test");
//Available methods:
myTimer.Refresh(); // Refreshes timer (stops and restarts)
myTimer.Cancel(); // Destructor
js code:
/*
    File: Timer.js
    Desc: Class for timer handling
*/
var Timers = {};
var nTimersCount = 0;

var Timer = function(nInterval, fCallback, oParam) {
    this.Interval = nInterval;
    this.Callback = fCallback;
    this.Index = nTimersCount++;
    if(typeof oParam !== "undefined") this.Param = oParam;
    Timers[this.Index] = this;
    MsgPlus.AddTimer('Timer'+this.Index, this.Interval);
}

Timer.prototype = {
    "Refresh" : function() {
        MsgPlus.AddTimer('Timer'+this.Index, this.Interval);
    },
    "Cancel" : function() {
        MsgPlus.CancelTimer('Timer'+this.Index);
        delete Timers[this.Index];
    }
}

function OnEvent_Timer(sTimerId) {
    if(/^Timer(\d+)$/.test(sTimerId)) {
        var nIndex = 1*RegExp.$1;
        if(typeof Timers[nIndex].Param === "undefined") Timers[nIndex].Callback(Timers[nIndex]);
        else Timers[nIndex].Callback(Timers[nIndex], Timers[nIndex].Param);
    }
}
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
09-20-2009 06:54 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Timeout Objects - by trevorpe on 09-19-2009 at 11:35 PM
RE: Timeout Objects - by roflmao456 on 09-20-2009 at 01:08 AM
RE: Timeout Objects - by Matti on 09-20-2009 at 06:54 AM
RE: Timeout Objects - by trevorpe on 09-20-2009 at 11:23 AM
RE: Timeout Objects - by Matti on 09-20-2009 at 05:47 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