Beck
06-26-2002, 10:56 PM
Just wandered if anyone has any ideas about storing objects for later calling by the window.setTimeout object. I want some object to be called over and over by the setTimeout function, and then it is paused, where the called object and its associated timer are both stored. When it's unpaused, they are released and called by the window.setTimeout to resume.
something like:
var game = false;
function FirstGuy () {
if (game) {
// do something
window.setTimeout("FirstGuy()",200);
} else {
pause.store (FirstGuy,200);
}
}
function Pause () {
this.calls = new Array ();
this.timers = new Array ();
this.num = 0;
this.store = pauseStore;
this.release = pauseRelease;
}
var pause = new Pause ();
function pauseStore (called,timer) {
this.calls[this.num] = called;
this.timers[this.num] = timer;
this.num++;
}
function pauseRelease () {
for (var i=0; i<this.num; i++) {
window.setTimeout(this.calls[i]+"()",this.timers[i]);
}
}
As you can see, pause is a stack which stores the recursive stuff when it is called,and then is supposed to release them to resume recursion when it is deactivated.
The problem is that I'm not sure how to store and release. I've tried these:
pause.store (FirstGuy,200);
pause.store ("FirstGuy",200);
window.setTimeout(pause.calls[i]+"()",this.timers[i]);
window.setTimeout("pause.calls[i]()",this.timers[i]);
So far, no cigar. Any suggestions would be greatly appreciated. Also, if anyone knows how to put a timeout on hold and then resume it, that's good also (still need the pause thing, though).
Thanks in advance.
something like:
var game = false;
function FirstGuy () {
if (game) {
// do something
window.setTimeout("FirstGuy()",200);
} else {
pause.store (FirstGuy,200);
}
}
function Pause () {
this.calls = new Array ();
this.timers = new Array ();
this.num = 0;
this.store = pauseStore;
this.release = pauseRelease;
}
var pause = new Pause ();
function pauseStore (called,timer) {
this.calls[this.num] = called;
this.timers[this.num] = timer;
this.num++;
}
function pauseRelease () {
for (var i=0; i<this.num; i++) {
window.setTimeout(this.calls[i]+"()",this.timers[i]);
}
}
As you can see, pause is a stack which stores the recursive stuff when it is called,and then is supposed to release them to resume recursion when it is deactivated.
The problem is that I'm not sure how to store and release. I've tried these:
pause.store (FirstGuy,200);
pause.store ("FirstGuy",200);
window.setTimeout(pause.calls[i]+"()",this.timers[i]);
window.setTimeout("pause.calls[i]()",this.timers[i]);
So far, no cigar. Any suggestions would be greatly appreciated. Also, if anyone knows how to put a timeout on hold and then resume it, that's good also (still need the pause thing, though).
Thanks in advance.