Need help with if then based on var in my Canvas game.

Community Beginner ,
Oct 30, 2020 Oct 30, 2020

Copy link to clipboard

Copied

On the main timeline I have 

 

var clickCount = 0;

In it's own movieclip I have this code so if a button is pressed it will increase the clickCount +1 and i want that if you reach 3 or more, it will tell another mc to go to a frame and play a frame name.

this.PumpkinButton.addEventListener("click", PumpkinDeath.bind(this));

function PumpkinDeath()
{
	exportRoot.clickCount ++;
	if (exportRoot.clickCount >= 3){
		exportRoot.trickOrTreatMovie.gotoAndPlay("gameOverNoPrize");
	}else{
	exportRoot.TriesRemainingMC.play();
	exportRoot.trickOrTreatMovie.play();
	this.gotoAndPlay(2);
}
}

But it's not working. What did I mistype?

Thanks ahead,

Line

//Signature// I'm a creator. I love illustration, designing, animating , writing, voice overs, acting, making games .. Woo woo!
TOPICS
Code

Views

85

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
community guidelines
Community Beginner ,
Oct 30, 2020 Oct 30, 2020

Copy link to clipboard

Copied

Hi Line.

 

Change exportRoot by e.target.parent  or  e.target.parent.parent or e.target.parent.parent.parent  Depending on the depth of the clicked button in relation to the stage.

 

// with this the target will ever the PumpkinButton and not a son of PumpkinButton
this.PumpkinButton.mouseChildren = false;

//the parameter 'e' must be entered for you to access the event trigger.
function PumpkinDeath(e)
{
	exportRoot.clickCount ++;
	if (exportRoot.clickCount >= 3){
             //this is the secret :)
		e.target.parent.trickOrTreatMovie.gotoAndPlay("gameOverNoPrize");
	}else{
	exportRoot.TriesRemainingMC.play();
	exportRoot.trickOrTreatMovie.play();
	this.gotoAndPlay(2);
}
}

 

 

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
community guidelines
Community Beginner ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

LATEST

Hi Murilo Flesch,

 

Thanks a lot for your reply.  I appreciate your reply and insight but with your reply I still have a lack of understanding it. I need to take a refresher course on programming JavaScript.

 

Thanks again!

 

Line

//Signature// I'm a creator. I love illustration, designing, animating , writing, voice overs, acting, making games .. Woo woo!

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
community guidelines
Adobe Community Professional ,
Oct 30, 2020 Oct 30, 2020

Copy link to clipboard

Copied

You declared clickCount wrong. Variables declared with var are private to the frame they're declared in. You need to make it a property.

 

exportRoot.clickCount = 0;

 

Also you really need to learn to check your browser's developer console for runtime errors.

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
community guidelines
Community Beginner ,
Nov 02, 2020 Nov 02, 2020

Copy link to clipboard

Copied

Hi ClayUUID,

 

Thanks for the info on how to make it a property.. When it's a property does that mean it's a globaly one?

 

I agree with you about the dev console. I actually had inquired about that in a previous forum post but no one replied so I am still in the dark on how to check.

 

Thanks again for your info and replies!

 

Line

//Signature// I'm a creator. I love illustration, designing, animating , writing, voice overs, acting, making games .. Woo woo!

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
community guidelines