Skip to main content
Known Participant
October 14, 2022
Question

switch case statement

  • October 14, 2022
  • 1 reply
  • 125 views

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 

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    October 18, 2022

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