Javascript problem - "crash browser" "infinite loop" timer

Discussion in 'Javascript' started by mkseekprog, Nov 14, 2017.

  1. mkseekprog

    mkseekprog

    Joined:
    Nov 14, 2017
    Messages:
    3
    Likes Received:
    0
    I have a rather thorny js problem. I should say Phaser/javascript problem.
    It was done in the phaser framework. And I have sen this before (but not this extreme). phaser works a lot better offline than online.
    Anyway, have a series of games they are all very similar with only slight differences. But they all crash the browser at the very end. Stranger still, they all work perfectly offline, and even stanger they make it to the end of the game - and then crash. There is a 21 second timer involved and I suspect that. For example:
    Makes it to a reset of the game, both online and off - no problem. Dumps the player back to the beginning.
    //resetGame();
    window.location = "../index.html";
    //end of game - different story - works offline, send player to endgame.html Online, crashes the browser, infinite loop, whatever you want to call it. Player NEVER gets to endgame.html

    if(flagGameover){
    console.log("GOTO GAMEOVER");
    window.location = "../endgame.html";
    }
    }
    }

    }
    Already been through this over and over, went back to the original code, yup, same problem.
    and the coder is no longer around. and I'm not a js expert.
    So what I'm looking for is a quick and dirty solution - abort the js go to the html page.
    It has done everything it was designed to do, except get out of it!
    I've read a few suggestions across the web, such as:
    function FatalError(){ Error.apply(this, arguments); this.name = "FatalError"; }
    ---------------------------
    function javascript_abort()
    --------------------------------
    function clearTimer() {
    clearInterval(intervalTimer);
    }
    -------------------------------
    So, I'm thinking (but don't know how) put a line or two of the above code onto the existing 21 second timer to completely stop it at 21 seconds and 'abort' the js send the user to endgame.html Don't need the js after the 21 seconds at all.

    //Here's the sections dealing with the timer:

    var maxTime = 21; //in SECOND var timerEvent = null;

    //This is where the timer gets added (after a 3 second animation at the beginning of the game)

    console.log("FINISH ANIMATION and ADD TIMER");

    //and this

    timerEvent = game.time.events.add(Phaser.Timer.SECOND * maxTime, moveToEndGame, this);
    },this);
    -----------> and THE END (or supposed to be the end)

    if(!flagGameover && !star.visible && idx_bullet < bullet_array.length)
    initBullet();
    else{
    if(flagGameover){
    console.log("GOTO GAMEOVER");
    window.location = "../endgame.html";
    }
    }
    }

    }
    Anyone done anything like this before? It would be useful to know, save a lot of time and headache. Like I said, the whole thing works until the very end, and it's accomplished everything - except end!
    Thanks
     
    mkseekprog, Nov 14, 2017
    #1
    1. Advertisements

  2. mkseekprog

    mkseekprog

    Joined:
    Nov 14, 2017
    Messages:
    3
    Likes Received:
    0

    I found out what it was.

    It was missing a callover, as in:

    var callGameover = false;
    and......
    if(flagGameover){
    if(callGameover == false){
    callGameover = true;
    console.log("GOTO GAMEOVER");
    window.location = "endgame.html";
    I didn't know that was enough to cause an "infinite loop" but apparently it was. Put the above in and loop gone!
     
    mkseekprog, Nov 19, 2017
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.