Hi, Everybody:
Ok! Round 2! I’m trying to create a poker game which the cards are shuffled to the players. I tried an program initially, but I fell flat on my face! You can see my initial question here: Trying to create an class array with two properties - Unity Answers
So I’m here again, trying to attack this problem another way. This time the program creates two array (cardContent and cardList), adds two items to cardContent, then adds the array cardContent to cardList. It compiles without errors, but it’s not giving me what I need. The results are:
p1.cardList: 10,D,10,D,10,D,10,D,10,D,10,D,10,D,10,D,10,D,10,D,10,D,10,D,10,D,10,D,10,D,10,D,10,D
p2.cardList:
10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S,10,S
It’s suppose to give me something like: 1,D,1,H,2,D,3,H, …
The coding is listed below. The cardContent seems to work, because Debug.Log on cardContent shows the right items, but it doesn’t seem to work when I try to add cardContent to cardList (i.e., cardList.Add(cardContent). Please help!
Thanks!
Supra411
#pragma strict
class Card {
var cardContent = new Array ();
var cardList = new Array ();
function AddCard (i : int, j : String) {
cardContent.Clear();
cardContent.Add(i);
cardContent.Add(j);
//Debug to see what's in cardContent.
Debug.Log(cardContent);
cardList.Add(cardContent);
}
}
//Set's array for suits when shuffling.
var suitKind = Array ("D", "C", "H", "S");
var p1 : Card;
var p2 : Card;
function PassCard (i : int, suit : String) {
if (Random.value <= .5) {
p1.AddCard(i, suit);
}
else {
p2.AddCard(i, suit);
}
}
function Start () {
for (var i=0; i<10; i++) {
for (var j=0; j<4; j++) {
var suit : String = suitKind[j];
PassCard (i+1, suit);
}
}
Debug.Log (p1.cardList);
Debug.Log (p1.cardList.length);
Debug.Log (p2.cardList);
Debug.Log (p2.cardList.length);
}