Chozo Qhai
Chozo Qhai

Reputation: 281

iMacro if else statement javascript

I'm faced a problem in my code. It keep repeat execute the first if statement but didn't check for the second if statement. Which it keep on show the message "I'm double from lose". Currently making a script, let say the image1 matches the screen image, it will proceed to stuff1, else if image2 matches with screen image proceed to stuff2.

   if(iimPlay("Lose.iim")>0) 
   {
    iimPlay("Double.iim");
   alert("I'm double from lose");

   }
   else if (iimPlay("Win.iim")>0)
   {
      iimPlay("Reset.iim");
   alert("I'm reset from Win");
   }

Upvotes: 0

Views: 2606

Answers (1)

aga
aga

Reputation: 29416

What happens is that after the first if condition evaluates to be true, all the following else if statements in the chain don't execute. Rewrite the second condition w/o else:

if (iimPlay("Win.iim") > 0)
{
   iimPlay("Reset.iim");
   alert("I'm reset from Win");
}

That way, even if the first if condition is true it'll try to evaluate the second if condition.

Upvotes: 1

Related Questions