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

Choose Your Own Adventure - HTML5 Buttons Help

New Here ,
Jul 09, 2020 Jul 09, 2020

This is a short game for a project. I was wondering if there was somehow a way for animate to "remember" / keep track of the button options chosen in order to lead to certain scenes.

I.e. Clicking more of the bad choice buttons will get you to the "bad end" sequence

For example I have 3 scenes, so clicking the bad option 2/3 times will trigger the bad end, at the end.

 

Can it be done? If so, what codes are needed to achieve this?

TOPICS
Code , How to , Timeline
448
Translate
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

correct answers 1 Correct answer

Community Expert , Jul 09, 2020 Jul 09, 2020

use a counter variable to record whow many times a button is clicked.

 

if(!this.counter){

this.counter=0;  // and reset wherever

}

 

yourbutton.addEventListener("click",yourbuttonlistenerF.bind(this));

function yourbuttonlistnerF(){

this.counter++;

if(this.counter>=2){

this.gotoAndStop("yourbadend");

}

}

}

Translate
Community Expert ,
Jul 09, 2020 Jul 09, 2020

use a counter variable to record whow many times a button is clicked.

 

if(!this.counter){

this.counter=0;  // and reset wherever

}

 

yourbutton.addEventListener("click",yourbuttonlistenerF.bind(this));

function yourbuttonlistnerF(){

this.counter++;

if(this.counter>=2){

this.gotoAndStop("yourbadend");

}

}

}

Translate
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 ,
Jul 09, 2020 Jul 09, 2020

Thank you so much! I'm very new to this, I appreciate it.

Translate
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 ,
Jul 09, 2020 Jul 09, 2020
LATEST

you're welcome.

Translate
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