• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

フレームが変わると変数が反映されません

New Here ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

例えば、1フレームに

var score = 0;

と変数を設定します。

2フレームにボタンを作成し、

this.btn_seikai_1.addEventListener("click", btn_seikai_1.bind(this));

function btn_seikai_1()
{
score = score+10;
this.score_txt.text = score;
}

として、ボタンをクリックしたら、10プラスされるようにしましたが、うまくいきません。

animateでは、変数はフレームが変わると反映されないのでしょうか。

教えていただけるとありがたいです。

 

Views

149

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2021 Apr 19, 2021

Copy link to clipboard

Copied

in thml5/canvas, variables prefixed by "var" are local to their frame.  if you want the variable to persist after it's defined, use:

 

this.score = 0;

 

if you do not want that variable reset when re-entering that frame, use:

 

if(!this.alreadyExecuted){

this.alreadyExecuted = true;

this.score = 0;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

丁寧に教えていただき、

ありがとうございました。

うまくいきました。

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 20, 2021 Apr 20, 2021

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines