-1

I have the following js code in a .php file:

var counter = 1;

function loadgame(wait_time) {
  var loadtext=document.getElementById( 'progressbarloadtext' ).style;
  var percentlimit = <?php echo tiguan_get_option( 'td_bar_textload_limit' ); ?>;
  var speedindex = <?php echo tiguan_get_option( 'td_bar_speed' ); ?>;
  var percentlimitstatus = "<?php echo tiguan_get_option( 'td_bar_textload_status' ); ?>";
  speedindex = speedindex*2;
  if ( counter < wait_time) {
    counter = counter + 1;
    document.getElementById("progressbarloadbg").style.width = counter + "px";
    var percentage = Math.round( counter / wait_time * 100);
    document.getElementById("progresstext").innerHTML = percentage+" %";
    window.setTimeout("loadgame('" + wait_time + "')", speedindex );
    if ( (percentage >= percentlimit) & (percentlimitstatus == 1 ) ) {
      loadtext.display='block';
    }
  }
  else {
    counter = 1;
    window.hide();
  }
}

function hide() {
  var showprogressbar=document.getElementById( 'showprogressbar' ).style;
  var loadtext=document.getElementById( 'progressbarloadtext' ).style;
  var game = document.getElementById( 'td-game-wrap' ).style;

  showprogressbar.display='none';
  loadtext.display='none';
  game.width = '100%';
  game.height = '100%';

  counter = 400;

}

Now, this is the code included in a theme-scripts.js file:

jQuery(document).ready(function($) {
    setTimeout('loadgame(400)', 0);
    });

The loadgame function is defined in the single.php WordPress file.

Inspecting the code with Firebug I get this error:

Uncaught referenceerror loadgame is not defined

Any tips to avoid thie error?

Thanks

Liviu Costache
  • 201
  • 2
  • 13
  • 1
    [Don't pass a string to `setTimeout`](http://stackoverflow.com/questions/6081560/is-there-ever-a-good-reason-to-pass-a-string-to-settimeout) – JJJ Aug 30 '16 at 15:26
  • @Juhana thanks but I'm not js developer. Can you point my how this code should be write to be correct? Post it as an answer pls.Thanks. – Liviu Costache Aug 30 '16 at 15:26
  • Without knowing where the `loadgame` function is defined, it's not possible to spoon-feed a solution. Read the question I linked to. – JJJ Aug 30 '16 at 15:28
  • `setTimeout(() => loadGame(400), 0);` –  Aug 30 '16 at 15:29
  • @Juhana updated the question to show where the loadgame function is defined, I hope you can help me now. Thanks. – Liviu Costache Aug 31 '16 at 14:01

1 Answers1

-1

The function "loadgame" doesn't exists in this scope. Add: function loadgame(x) { } to your code to get rid of the error. Unfortunately, that doesn't solve the problem.

Flocke
  • 764
  • 6
  • 14
  • 1
    I didn't downvoted you answer, but if you don't know how to answer or not enough informations are provided to post an answer, better don't write it. –  Aug 30 '16 at 15:31