Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by obadelej · Oct 16, 2018 at 12:40 AM · bug

How to locate bug that keeps occuring on and off?

Hi all, I am creating a playing card game called All Fours. I have almost finish the gameplay but has been having a bug that seems to be occurring on and off. Most of the time the game plays as it is supposed to but ever so often it does not do what it supposed to.

I check the cards played in a coroutine called CheckTrick. After both players play the CheckTrick coroutine checks to see which player wins the trick, assign the played cards to the winner and selects the winner of the trick to play first on the next turn. Most of the time it works as it should but once in a while the player that is supposed to win the trick doesnt get the leaf and the one that suppose to lose the trick gets the leaf and the turn to play.

I have tried debgugging in visual sutsio to find the bug but can't seem to recreate the situation to track it. I am wondering if its the cocorutine that is causing the problem.

Here is my CheckTrick Coroutine public IEnumerator CheckTrick(List cards, int player) { // pause for 3 seconds yield return new WaitForSeconds(3f);

         // if ther are cards and the gameState is Checktrick
         if (cards != null && gameState == GameState.CheckTrick)
         {
             // if player1 played the last card of the trick
             if (player == 1)
             {
                 // if Player1 jack gets hang when he plays last
                 if ((cards[0].GetCardSuit() == trump.GetCardSuit() && (int)cards[0].GetCardValue() >= 12) &&
                     (cards[1].GetCardSuit() == trump.GetCardSuit() && cards[1].GetCardValue() == CardValue.Jack))
                 {                    
                     Player2HangJack();
                     yield return StartCoroutine(HangJackPause());    // Call the HangJackPause Coroutine
                     gameState = GameState.SettingUp;                // Change the gameState to setting up
                     yield return null;                                // Return 
                 }
                 else if ((cards[0].GetCardSuit() == trump.GetCardSuit() && cards[0].GetCardValue() == CardValue.Jack) &&
                     (cards[1].GetCardSuit() == trump.GetCardSuit() && (int)cards[1].GetCardValue() >= 12))
                 {                    
                     Player1HangJack();
                     yield return StartCoroutine("HangJackPause");
                     gameState = GameState.SettingUp;
                     yield return null;
                 }
                 // if the two played cards have different suits and player1 card is not trump
                 if (cards[1].GetCardSuit() != cards[0].GetCardSuit() && cards[1].GetCardSuit() != trump.GetCardSuit())
                 {
                     Player2WinsTrick();
                 }
                 // if the two played cards are of different suit and player1 card is trump
                 else if (cards[1].GetCardSuit() != cards[0].GetCardSuit() && cards[1].GetCardSuit() == trump.GetCardSuit())
                 {
                     Player1WinsTrick();
                 }
                 // if the two played cards have the same suit and player1 card is greater
                 else if (cards[1].GetCardSuit() == cards[0].GetCardSuit() && (int)cards[1].GetCardValue() > (int)cards[0].GetCardValue())
                 {
                     Player1WinsTrick();
                 }
                 // if the two played cards have the same suit and player1 card value is less
                 else if (cards[1].GetCardSuit() == cards[0].GetCardSuit() && (int)cards[1].GetCardValue() < (int)cards[0].GetCardValue())
                 {
                     Player2WinsTrick();
                 }
                 StopCoroutine(myCheckTrick);
             }
             // if player2 played the last card in the trick
             else if (player == 2)
             {
                 // if Player2 jack gets hang when he plays last
                 if ((cards[0].GetCardSuit() == trump.GetCardSuit() && (int)cards[0].GetCardValue() >= 12) &&
                     (cards[1].GetCardSuit() == trump.GetCardSuit() && cards[1].GetCardValue() == CardValue.Jack))
                 {
                     Player1HangJack();
                     yield return StartCoroutine("HangJackPause");
                     gameState = GameState.SettingUp;
                     yield return null;
                 }
                 // if player 1 jack gets hang when he plays first
                  else if ((cards[0].GetCardSuit() == trump.GetCardSuit() && cards[0].GetCardValue() == CardValue.Jack) &&
                     (cards[1].GetCardSuit() == trump.GetCardSuit() && (int)cards[1].GetCardValue() >= 12))
                 {
                     Player2HangJack();
                     yield return StartCoroutine("HangJackPause");
                     gameState = GameState.SettingUp;
                     yield return null;
                 }
                 // if the two played cards have different suits and player2 card is not trump
                 if (cards[1].GetCardSuit() != cards[0].GetCardSuit() && cards[1].GetCardSuit() != trump.GetCardSuit())
                 {
                     Player1WinsTrick();
                 }
                 // if the two played cards are of different suit and player2 card is trump 
                 else if (cards[1].GetCardSuit() != cards[0].GetCardSuit() && cards[1].GetCardSuit() == trump.GetCardSuit())
                 {
                     Player2WinsTrick();
                 }
                 // if the two played cards have the same suit and player2 card is greater
                 else if (cards[1].GetCardSuit() == cards[0].GetCardSuit() && (int)cards[1].GetCardValue() > (int)cards[0].GetCardValue())
                 {
                     Player2WinsTrick();
                 }
                 // if the two played cards have the same suit and player2 card value is less
                 else if (cards[1].GetCardSuit() == cards[0].GetCardSuit() && (int)cards[1].GetCardValue() < (int)cards[0].GetCardValue())
                 {
                     Player1WinsTrick();
                 }
                 StopCoroutine(myCheckTrick);
             }
             //StopCoroutine(myCheckTrick);
             yield return StartCoroutine(AfterCheckTrickPause());    // 
 
             playedCards.Clear();        // clear the played cards list
             CheckHand();                // check the hand to see if the players have any cards left. (If they dont then set the scoring state)            
         }
     }


Can someone look over my code and see if they can Identify what I might have done wrong here and give suggestions as to how I can do this better to avoid this bug.

@LeonardNS can you check it out for me?

alt text

checktrick.png (122.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

159 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My game starts with a white screen on a player's screen. Music on, mouse cursor okay but nothing else. 0 Answers

Index was out of range. error 1 Answer

Bug - circular shadow from unknwon source under camera, with size of shadow distance from quality settings 1 Answer

Unity's Editor UI Frozen/ Not updating, Video included 0 Answers

Weird texture behaving on flat object 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges