problem with and statement or some other issue

I’m looking for some help with the below code. The Debug shows the output fine for activecarda and activecardb but the problem is with the bottom section of the code, I cannot get it to show “matchfound”. I tried using && statement instead of nesting if statements, same issue. any ideas what i’m doing wrong?

if (this.tag==“card1”)
{
activecarda=1;
Debug.Log("activecarda "+activecarda);
}

if (this.tag==“card9”)
{
activecardb=9;
Debug.Log("activecardb "+activecardb);
}

//this is the problem below, doesnt print matchfound, tried using && loop but same issue

if (activecarda==1)
{
if (activecardb==9)
{
Debug.Log(“matchfound”);
}
}

Please use code tags.

if (activecarda==1) {
     if (activecardb==9) {
          Debug.Log("matchfound");
     }
}

The code looks fine, maybe activecarda & activecardb aren’t set to the correct values for it to debug the match?

Can you should me the console when you try to do this?
Like, make sure that both cards are activated… o_o

The debug log shows values 1 for activecarda and 9 for activecardb. I tried your code above and same issue, doesnt print matchfound

I’m using this code within function OnMouseDown() , could this be part of the problem.

The code should be working.
Make the booleans public, and see if they are both true in the unity inspector.

made sure the variables were public, added a screenshot of the debug to show it does show the values of the 2 cards ok…

Is all the code you pasted in the same function? Are activecarda and activecardb static? Can you show us the whole class? (Use the CODE tags!) I have a feeling the error is not in the code you have shown us but somewhere else.

Code below, I am using android format, could it be anything to do with that, I dont get any errors though…

function OnMouseDown () {

   if (this.tag=="card1")
   {
   animation.Play("anim3");
   activecarda=1;
   Debug.Log("activecarda "+activecarda);
   }
   
   if (this.tag=="card9")
   {
   animation.Play("anim3");
   activecardb=9;
   Debug.Log("activecardb "+activecardb);
   }
   
   
   if (activecarda==1)
     {
       if (activecardb==9)
         {
           Debug.Log("matchfound");
           //print ("escape pressed");
           //Application.Quit();
         }
     }

}

I’ve manged to get it working, it was to do with the public variable, I thought I done it right by putting

public var activecarda

but had to put

static var activecarda

I think I’ll have to read up on how these variables work within functions as I have other variables declared which work fine within other functions which were declared the same way as activecarda and activecardb

Thanks for your help, much appreciated.

Yeah, so you’ve attached the same script on different objects, just like @GarthSmith suggested.
The problem the two scripts had different booleans.
So one of the two booleans would always be false in any instance of the script.
Changing it to a static variable made it so the variable is shared over all instances.
People often use a manager script to save values that are supposed to be shared.
You’ll avoid making this mistake doing so, because there’s only supposed to be 1 instance of a manager script.