Question by
KingNate · Jan 12, 2016 at 06:33 AM ·
if-statements
Why does my if statement skip the body even when the response is true?
even when if (TempPatternCheck [i] == true) is true is still skips the body of the if statement.
public int CalculateScore (Player p)
{
score = 0;
GetPlayerHand (p);
CheckPattern ();
for (int i = 0; i < 8; i++) {
// counter += i;
int[] j = new int[3];
j [0] = patternCheck [i, 0];
j [1] = patternCheck [i, 1];
j [2] = patternCheck [i, 2];
//This is the if statement its skipping the body of
if (TempPatternCheck [i] == true) {
if (TempHand [j [0]].Definition.Text == "Joker" || TempHand [j [0]].Definition.Text == "PotOfGold") {
if (TempValue [j [1]] == TempValue [j [2]]) {
//TempValue [patternCheck [i, 0]] = 0;
TempValue [patternCheck [i, 1]] = 0;
TempValue [patternCheck [i, 2]] = 0;
}
} else if (TempHand [j [1]].Definition.Text == "Joker" || TempHand [j [1]].Definition.Text == "PotOfGold") {
if (TempValue [j [0]] == TempValue [j [2]]) {
TempValue [patternCheck [i, 0]] = 0;
//TempValue [patternCheck [i, 1]] = 0;
TempValue [patternCheck [i, 2]] = 0;
}
} else if (TempHand [j [2]].Definition.Text == "Joker" || TempHand [j [2]].Definition.Text == "PotOfGold") {
if (TempValue [j [0]] == TempValue [j [1]]) {
TempValue [patternCheck [i, 0]] = 0;
TempValue [patternCheck [i, 1]] = 0;
//TempValue [patternCheck [i, 2]] = 0;
}
} else if (TempHand [j [0]] == TempHand [j [1]] && TempHand [j [0]] == TempHand [j [2]]) {
TempValue [patternCheck [i, 0]] = 0;
TempValue [patternCheck [i, 1]] = 0;
TempValue [patternCheck [i, 2]] = 0;
}
}
}
for (int k = 0; k < 9; k++) {
if (TempValue [k] > 10) {
score += 10;
} else {
score += TempValue [k];
}
}
TempPatternCheck.Clear ();
return score;
}
Comment
So I went and changed my code for some logging output. the console output is as follows
public int CalculateScore (Player p)
{
score = 0;
GetPlayerHand (p);
CheckPattern ();
for (int i = 0; i < 8; i++) {
// counter += i;
int[] j = new int[3];
j [0] = patternCheck [i, 0];
j [1] = patternCheck [i, 1];
j [2] = patternCheck [i, 2];
Debug.Log (TempPatternCheck [i]);
if (TempPatternCheck [i] == true) {
Debug.Log ("inside (TempPatternCheck [i])");
Debug.Log (TempHand [j [0]].Definition.Text + " : " + TempHand [j [0]].Definition.Text == "PotOfGold");
Debug.Log (TempHand [j [1]].Definition.Text + " : " + TempHand [j [1]].Definition.Text == "PotOfGold");
Debug.Log (TempHand [j [2]].Definition.Text + " : " + TempHand [j [2]].Definition.Text == "PotOfGold");
if (TempHand [j [0]].Definition.Text == "Joker" || TempHand [j [0]].Definition.Text == "PotOfGold") {
if (TempValue [j [1]] == TempValue [j [2]]) {
//TempValue [patternCheck [i, 0]] = 0;
TempValue [patternCheck [i, 1]] = 0;
TempValue [patternCheck [i, 2]] = 0;
}
} else if (TempHand [j [1]].Definition.Text == "Joker" || TempHand [j [1]].Definition.Text == "PotOfGold") {
if (TempValue [j [0]] == TempValue [j [2]]) {
TempValue [patternCheck [i, 0]] = 0;
//TempValue [patternCheck [i, 1]] = 0;
TempValue [patternCheck [i, 2]] = 0;
}
} else if (TempHand [j [2]].Definition.Text == "Joker" || TempHand [j [2]].Definition.Text == "PotOfGold") {
if (TempValue [j [0]] == TempValue [j [1]]) {
TempValue [patternCheck [i, 0]] = 0;
TempValue [patternCheck [i, 1]] = 0;
//TempValue [patternCheck [i, 2]] = 0;
}
} else if (TempHand [j [0]] == TempHand [j [1]] && TempHand [j [0]] == TempHand [j [2]]) {
TempValue [patternCheck [i, 0]] = 0;
TempValue [patternCheck [i, 1]] = 0;
TempValue [patternCheck [i, 2]] = 0;
}
}
}
for (int k = 0; k < 9; k++) {
if (TempValue [k] > 10) {
score += 10;
} else {
score += TempValue [k];
}
}
TempPatternCheck.Clear ();
return score;
}
unity-console.jpg
(58.7 kB)
Best Answer
Answer by KingNate · Jan 12, 2016 at 07:09 AM
I fixed it, I was testing for true against the wrong thing.
Your answer
Follow this Question
Related Questions
mathf.abs(0) is higher than 90, why? 1 Answer
Can't Locate gameobject in array 3 Answers
problem with lists 0 Answers
[Solved] Error in this code? 2 Answers
Infinite Time inbetween if statements? 2 Answers