Skip to main content
Participant
July 9, 2020
Answered

Choose Your Own Adventure - HTML5 Buttons Help

  • July 9, 2020
  • 1 reply
  • 486 views

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?

This topic has been closed for replies.
Correct answer kglad

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");

}

}

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
July 9, 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");

}

}

}

Rakun99Author
Participant
July 10, 2020

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

kglad
Community Expert
Community Expert
July 10, 2020

you're welcome.