0

I have html5 score base game. when game over, end screen shows total score via the below function:

this.show = function (a)
{
    b.text = TEXT_GAMEOVER;
    e.text = TEXT_SCORE + ": " + a;
    d.visible = !0;
};

Now i want to get total score that is a or e.text in the onclick button release function:

var a;
this._onButSendRelease = function ()
{ 
       console.log(a);
}

but a is undefined, Please help me how i can do that.

1
  • function (a) will create a new local variable a and will not change your exisitng a variable. Commented Mar 2, 2018 at 16:13

1 Answer 1

1

You can simply store your score in a variable declared in the global scope :

var score; //Declare your variable here

this.show = function (a)
{
    b.text = TEXT_GAMEOVER;
    e.text = TEXT_SCORE + ": " + a;
    score = a; //Populate your variable here
    d.visible = !0;
};

this._onButSendRelease = function ()
{
    console.log(score); //Display your variable here
}
Sign up to request clarification or add additional context in comments.

1 Comment

i tried this but i'm getting this in console a {_listeners: null, _captureListeners: null, alpha: 1, cacheCanvas: null, cacheID: 0, …}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.