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);
}
}