Web Analytics Made Easy -
StatCounter Storing objects for later call - CodingForum


No announcement yet.

Storing objects for later call

  • Filter
  • Time
  • Show
Clear All
new posts

  • Storing objects for later call

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

    function pauseRelease () {
    for (var i=0; i<this.num; 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);


    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.
    If at first you don't succeed, spend more time online researching javascript!

  • #2
    no quite there, though

    Thanks, Dave, but the problem is a little more complicated than that. What you're saying will work, but imagine having well over a dozen timeouts taking place at once (making a video game, basically) and when the player pauses the game, I want to store these timeouts until the game resumes. I never know what bullets are on the page, what enemies are in action, etc, and all of them need to hault when paused and pick up where left off when unpaused.

    Technically I could hardcode all sorts of checks, etc, but then I'd even have to modify like crazy to change even one object. The more generic stack storage idea doesn't require any modifications.

    So if anyone's got anything for me to think about, fire away!

    If at first you don't succeed, spend more time online researching javascript!