• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

switch case statement

Community Beginner ,
Oct 14, 2022 Oct 14, 2022

Copy link to clipboard

Copied

Dear all thank you for your time

I have a function called control  I use to reset a game using a set interval clear interval process. I would like to stop the reset function working at certain times to allow another function to execute. I have tried using a switch and else if statements but cant seem  get the right result, the console . log does not appear in the console if currentFrame is 0.So the concept is when the movie clip current frame is 9 the control function stops when at 0 the functions are allowed.I find the console only responds to the true function.

function control(){
	
	switch(true) 
	{
  case true:if(this.overided_mc.currentFrame==(9)){
   console.log ("overided")
// other movie clips do not act
  }
	  break;

  case false :if(this.overided_mc.currentFrame==(0)){
   console.log ("not overiden")
//other movie clips react to this order
}	
 
 }
 }

 Best Regards Peter 

Views

53

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 Expert ,
Oct 18, 2022 Oct 18, 2022

Copy link to clipboard

Copied

LATEST

your conditional switch isn't very much of a conditional.  it's a flat-out true, so it's branch is always going to executed.  

 

ie, you don't understand how to use switch/case:

 

https://www.w3schools.com/js/js_switch.asp

 

function control(){
switch(this.overided_mc.currentFrame==(9)){
case true:
console.log ("overiden");
// other movie clips do not act
break;

case false :
console.log ("not overiden");
//other movie clips react to this order
}
}

 

// or, imo, better:

 

function control(){
switch(this.overided_mc.currentFrame){
case 9:
console.log ("overiden");
// other movie clips do not act
break;

case 0 :
console.log ("not overiden");
//other movie clips react to this order
}
}

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