If two PlayerPrefs are on?

So I am having this issue where if I call upon one playerpref it works fine, and if I call upon a different playerpref it also works fine, but if I call upon both of them, it no longer works. I understand what I am saying is confusing, so here is an example:

function Update ()
{
if (PlayerPrefs.GetInt(“aPP1”)==1)
{

	}
	
	else if (PlayerPrefs.GetInt("aPP2")==1)
	{

	}
	
	else if ((PlayerPrefs.GetInt("aPP1")==1) && (PlayerPrefs.GetInt("aPP2")==1))
	{

	}
	
	else if ((PlayerPrefs.GetInt("aPP1")==0) && (PlayerPrefs.GetInt("aPP2")==0))
	{

	}
}

Now the wierd thing is is that when both playerprefs are set to zero, the last else if works just fine. But if they are both set to “1” the second else if does not work and instead only does the first else if.

How would I go about fixing this?

This is a logical problem. You’re first checking for a value of 1 from each pref separately, else if it is not then you’re checking both of them. That makes no sense, the single check will always return true before you check them both (no fall-through occurs).

The way to fix this would be to put the double checks before the single ones. I’m not sure that I’m explaining well enough, so here is an example:

         if ((PlayerPrefs.GetInt("aPP1")==1) && (PlayerPrefs.GetInt("aPP2")==1))
         {
       
         }
         else if ((PlayerPrefs.GetInt("aPP1")==0) && (PlayerPrefs.GetInt("aPP2")==0))
         {
       
         }
         else if (PlayerPrefs.GetInt("aPP1")==1) 
         {
       
         }
         else if (PlayerPrefs.GetInt("aPP2")==1)
         {
       
         }

The only other option is to restructure this whole statement entirely, which it kind of needs.

The problem here is the order of your conditions. Let’s walk through the code together.

int aPP1 = 1;
int aPP2 = 1;

Now check the first if(). Is aPP1 equal to 1? If your answer is yes(true) then the rest of the condition checks will be ignored. So the order of your condition checks matters.

You need to do it this way:

if ( PlayerPrefs.GetInt("aPP1") == 1 && PlayerPrefs.GetInt("aPP2") == 1 ) {
}else if (PlayerPrefs.GetInt("aPP1") == 1){
}else if (PlayerPrefs.GetInt("aPP2") == 1){
}else if ( PlayerPrefs.GetInt("aPP1") == 0 && PlayerPrefs.GetInt("aPP2") == 0 ){
}