Highlighted

Choose Your Own Adventure - HTML5 Buttons Help

New Here ,
Jul 09, 2020

Copy link to clipboard

Copied

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?

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

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

}

}

}

TOPICS
Code, How to, Timeline

Views

50

Likes

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

Choose Your Own Adventure - HTML5 Buttons Help

New Here ,
Jul 09, 2020

Copy link to clipboard

Copied

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?

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

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

}

}

}

TOPICS
Code, How to, Timeline

Views

51

Likes

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
Jul 09, 2020 0
Adobe Community Professional ,
Jul 09, 2020

Copy link to clipboard

Copied

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

}

}

}

Likes

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
Reply
Loading...
Jul 09, 2020 1
New Here ,
Jul 09, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Jul 09, 2020 0
kglad LATEST
Adobe Community Professional ,
Jul 09, 2020

Copy link to clipboard

Copied

you're welcome.

Likes

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
Reply
Loading...
Jul 09, 2020 0