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

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

Explorer ,
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

180

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

 

 

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
Explorer ,
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!

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
LEGEND ,
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.

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
Explorer ,
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!

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