Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Cannot hold the value of struct variable
    primarykey
    data
    text
    <p>I am trying to write a frame program that allows you to play Texas Hold'em Poker. And I am having trouble with function <code>hasPair</code> that decides if <code>CurrentPlayer</code> has a Pair:</p> <pre><code> public bool hasPair(Player CurrentPlayer) { bool flag; Card[] SevenCards = new Card[7]; SevenCards[0].Color = CurrentPlayer.Card1.Color; SevenCards[0].Number = CurrentPlayer.Card1.Number; SevenCards[1].Color = CurrentPlayer.Color2; SevenCards[1].Number = CurrentPlayer.Number2; SevenCards[2] = Ground.Card1; SevenCards[3] = Ground.Card2; SevenCards[4] = Ground.Card3; SevenCards[5] = Ground.Card4; SevenCards[6] = Ground.Card5; flag = isThere_Pair(SevenCards); return flag; } </code></pre> <p>And here is how <code>CurrentPlayer</code> receives its cards:</p> <pre><code> public void Deal_Cards(Player Player) { int Color1, No1, Color2, No2; while (true) { dealhelper1: Color1 = (RandomColor.Next() % 4); No1 = ((RandomNo.Next() % 13)); if (CardDeck[Color1, No1].isChosen == true) { goto dealhelper1; } if (CardDeck[Color1, No1].isChosen == false) { Player.Card1.Color = Color1; Player.Card1.Number = No1+1; Player.Card1.imagePath = CardDeck[Color1, No1].imagePath; Player.Color1 = CardDeck[Color1, No1].Color; Player.Number1 = CardDeck[Color1, No1].Number; CardDeck[Color1, No1].isChosen = true; break; } } while (true) { dealhelper2: Color2 = (RandomColor.Next() % 4); No2 = ((RandomNo.Next() % 13)); if (CardDeck[Color2, No2].isChosen == true) { goto dealhelper2; } if (CardDeck[Color2, No2].isChosen == false) { CardDeck[Color2, No2].isChosen = true; Player.Card2.Color = Color2; Player.Card2.Number = (No2)+1; Player.Color2 = CardDeck[Color2, No2].Color; Player.Number2 = CardDeck[Color2, No2].Number; break; } } display_Player_Cards(Player); } </code></pre> <p>But in the <code>hasPair</code> function, <code>CurrentPlayer</code>'s cards' numbers and colors are 0. I tried it in different ways but when I ask in a query, i cannot get the player cards' number values, although they have been initialized by the <code>Deal_Cards</code> function. Ground's cards have no problem, though.</p> <p>interestingly, <code>display_Player_Cards(Player)</code> function works correctly (so it takes the values successfully and displays the cards) .</p> <p>I use public variables of type <code>Player</code> (struct) like:</p> <pre><code> public Player P1 = new Player(); public Player AI = new Player(); </code></pre> <p>Why can't they hold their values? How can I solve this issue? Thanks for help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload