0

Problem: Hello i'm a little stuck as to why setTimeout() does not call the function specified after the time passed I've tried a few things but nothing seems to work

Solution: If anyone knows any other way to call a function after a specific time

Here is my code :

      refreshStats: function(){
        this.goldLabel.text = Math.floor(this.player.data.gold);
        this.attackLabel.text = Math.floor(this.player.data.attack);
        this.defenseLabel.text = Math.floor(this.player.data.defense);

        if (this.player.questsDone.length > 0){
            console.log(this.player.questsDone)
            this.bpText.text = this.player.questsDone[this.player.questsDone.length-1];
            setTimeout(this.FadeConsoleText(), 5000);
        }


      },
      FadeConsoleText: function(){
        console.log("log");
      },

Current output: "Quest" "a" wanted Solution output: "Quest" (wait then call function) "a"

Thank you in advanced

JasperDaDolphin
  • 172
  • 1
  • 9
  • Have a look at all these questions: [`[javascript] settimeout immediately`](https://stackoverflow.com/search?q=%5Bjavascript%5D+settimeout+immediately) – Felix Kling Apr 28 '17 at 04:53

1 Answers1

1

You want to pass the function, not what the function returns to setTimeout:

setTimeout(this.FadeConsoleText, 5000);
Blue
  • 22,608
  • 7
  • 62
  • 92