Why are these IF statements not working?:

Ae these if statements constructed properly?

/
/
/
if ((DealerTotalLogic.playerTotal > PlayerTotalLogic.playerTotal)  (DealerTotalLogic.playerTotal < 25) || (DealerTotalLogic.playerTotal < 25)  (PlayerTotalLogic.playerTotal > 25))
        {
            playersTOTALmoney -= playersBETamount;
        }
        if ((PlayerTotalLogic.playerTotal > DealerTotalLogic.playerTotal  PlayerTotalLogic.playerTotal < 25) || (PlayerTotalLogic.playerTotal < 25)  (DealerTotalLogic.playerTotal > 25))
        {
            playersTOTALmoney = playersTOTALmoney + playersBETamount;
        }
/
/
/

From my first glance I would say too many parentheses. The if statements are being done to check all those conditions right? So you would keep all those conditions within the same set of parentheses for that if statement. So more like this.

if (DealerTotalLogic.playerTotal > PlayerTotalLogic.playerTotal  DealerTotalLogic.playerTotal < 25 || DealerTotalLogic.playerTotal < 25  PlayerTotalLogic.playerTotal > 25)

It still isn’t calculating the playersTOTALmoney correctly.

The if as statement looks fine, but what do you intent to do? Tell me what is the logic or behavior you expect. When player win and when player looses?

Note that both IF are independent and that is precendente over || (evaluated first).

Note that nothing happens IF

  1. Dealer and Player are greater then 25
  2. Dealer and Player are equal
  3. Dealer and Player are equal to 25

Also depends where are you running this script. If you are running any turn, the if will execute with any number less than 25.

The IF you build says that

Player Looses IF
DealerTotal is less then 25 AND
Greater then PlayerTotal OR PlayerTotal greater then 25

Player Win IF
PlayerTotal less then 25 AND
Greater then DealerTotal OR DealerTotal Greater then 25

Is that what you want to do?

Tell us:
Where this script is running (Call after a round, after finish cards, at Update, …)?
What is the logic? When Player win? When Player looses?

It is called in its own function-

/
/
/
void dealerHIT()
    {
        dealerTotalguiTexture.guiText.enabled = true;
        dealersFlipcard.transform.rotation = Quaternion.Euler(0, 180, 0);
        if (DealerTotalLogic.playerTotal < 17)
        {
            dealersHcards();
            StartCoroutine(dealerHITnow());
            endGame();
        }
    }
    IEnumerator dealerHITnow()
    {
        yield return new WaitForSeconds(dealHITtime);
        {
            if (DealerTotalLogic.playerTotal < 17)
            {
                dealersHcards();
                StartCoroutine(dealerHITnowtwo());
                endGame();
            }
        }
    }
    IEnumerator dealerHITnowtwo()
    {
        yield return new WaitForSeconds(dealHITtime);
        {
            if (DealerTotalLogic.playerTotal < 17)
            {
                dealersHcards();
                StartCoroutine(dealerHITnowthree());
                endGame();
            }
        }
    }
    IEnumerator dealerHITnowthree()
    {
        yield return new WaitForSeconds(dealHITtime);
        {
            if (DealerTotalLogic.playerTotal < 17)
            {
                dealersHcards();
                StartCoroutine(dealerHITnowfour());
                endGame();
            }
        }
    }
    IEnumerator dealerHITnowfour()
    {
        yield return new WaitForSeconds(dealHITtime);
        {
            if (DealerTotalLogic.playerTotal < 17)
            {
                dealersHcards();
                endGame();
            } 
        }
    }
    // End Game Logic
    void endGame()
    {
        if (DealerTotalLogic.playerTotal > PlayerTotalLogic.playerTotal  DealerTotalLogic.playerTotal < 25 || DealerTotalLogic.playerTotal < 25  PlayerTotalLogic.playerTotal > 25)
        {
            playersTOTALmoney -= playersBETamount;
        }
        if (PlayerTotalLogic.playerTotal > DealerTotalLogic.playerTotal  PlayerTotalLogic.playerTotal < 25 || PlayerTotalLogic.playerTotal < 25  DealerTotalLogic.playerTotal > 25)
        {
            playersTOTALmoney = playersTOTALmoney + playersBETamount;
        }
    }
/
/
/

Yes.

I notice You will have many endGame calls after calling dealerHITnowtwo, dealerHITnowthree, dealerHITnowfour. I guess you should have endGame call only at the dealerHIT.

Any way include a Debug.Log (“Dealer:” + DealerTotalLogic.playerTotal + “Player:” + PlayerTotalLogic.playerTotal + “Money:” + playersTOTALmoney) before, inside and outside each if at endGame and will be much easier to get the bug.

I will try that right now.

I put the endGame in just the top function and it didn’t work. Still working wierd. Not sure why this isn’t working.

Try put the debug.log and show me here the results.

What is the “Player.” and “Dealer.” suppose to be???

Have you written this code?

you can’t just give us a snippet of code and ask “what is wrong”. If it isn’t a simple syntax problem then we need more. It sounds like you have som sort of logical problem.

You need to debug:

if ((DealerTotalLogic.playerTotal > PlayerTotalLogic.playerTotal)  (DealerTotalLogic.playerTotal < 25) || (DealerTotalLogic.playerTotal < 25)  (PlayerTotalLogic.playerTotal > 25))

        {

            playersTOTALmoney -= playersBETamount;

        }

        if ((PlayerTotalLogic.playerTotal > DealerTotalLogic.playerTotal  PlayerTotalLogic.playerTotal < 25) || (PlayerTotalLogic.playerTotal < 25)  (DealerTotalLogic.playerTotal > 25))

        {

            playersTOTALmoney = playersTOTALmoney + playersBETamount;

        }

so before the if-statement insert your debug.

Debug.Log(DealerTotalLogic.playerTotal);
Debug.Log(PlayerTotalLogic.playerTotal);

if ((DealerTotalLogic.playerTotal > PlayerTotalLogic.playerTotal)  (DealerTotalLogic.playerTotal < 25) || (DealerTotalLogic.playerTotal < 25)  (PlayerTotalLogic.playerTotal > 25))

        {

            playersTOTALmoney -= playersBETamount;

        }

        if ((PlayerTotalLogic.playerTotal > DealerTotalLogic.playerTotal  PlayerTotalLogic.playerTotal < 25) || (PlayerTotalLogic.playerTotal < 25)  (DealerTotalLogic.playerTotal > 25))

        {

            playersTOTALmoney = playersTOTALmoney + playersBETamount;

        }

then remove each condition in the if-statement to see if it validates or not, then add a condition, and then add the next condition… step by step debugging.

you need more brackets

if (DealerTotalLogic.playerTotal > PlayerTotalLogic.playerTotal  DealerTotalLogic.playerTotal < 25 || DealerTotalLogic.playerTotal < 25  PlayerTotalLogic.playerTotal > 25)

Group them into logical pairs

if ( (DealerTotalLogic.playerTotal > PlayerTotalLogic.playerTotal DealerTotalLogic.playerTotal < 25) ||
(DealerTotalLogic.playerTotal < 25 PlayerTotalLogic.playerTotal > 25) )

That way you don’t need to worry about operator ordering

Try splitting the conditions as hpjohn said but keep the parts together as they are dependent on each other.

Also note that you can debug as Toerktumlare said.

Debug.Log(WhatYouWantToFindRightHere);

That way if the variable isn’t changing you can see what it is at least and find where the error is happening. Also make sure the variables you are using there (playersTOTALmoney and playersBETamount) actually have a value. If both return with a value, then the problem is in the conditions of your if statement. Could be wording/logic. If this is the case then focus on the conditions of that if statement.

I have already tried more brackets HPJohn.

I am deploying this to an android device. not sure how I debug on it. I can’t on my PC because all the controls are set up for touch.

I haven’t used debugging much as I never needed to use except for a couple times…thanks for making me do it, I now see how it helps.

I created some gui buttons and debugged it. For some reason the dealers cards are not calculatingwhen they’re added to the hand…:expressionless:

It is calculating the amounts right but the if statements are still not processing them right.

then start removing the conditions one by one. Have first a simple condition. Then add another, and then add a third and whenever it fails. Then bob’s your uncle.

I have tried that.

In the conaole the debug log repeats constantly and other times it is just one set.

I just added a debug log to the if statements and they are not even being fired…:expressionless: