here you go, stim–i guess i’ve got nothing better to do on a cold sunday, so i worked this out for you:
it’s better to create an array of all 52 cards–it makes tracking them easier than using suits, where you’d have to do lots of checking when creating the card combos (this method would be good if you didn’t have to track a deck of 52)
//first make your cardArray
cardArray= ["2 of Hearts", "3 of Hearts","4 of Hearts", "5 of Hearts", "6 of Hearts", "7 of Hearts", "8 of Hearts", "9 of Hearts", "10 of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts", "Ace of Hearts","2 of Diamonds", "3 of Diamonds","4 of Diamonds", "5 of Diamonds", "6 of Diamonds", "7 of Diamonds", "8 of Diamonds", "9 of Diamonds", "10 of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds", "Ace of Diamonds","2 of Spades", "3 of Spades","4 of Spades", "5 of Spades", "6 of Spades", "7 of Spades", "8 of Spades", "9 of Spades", "10 of Spades", "Jack of Spades", "Queen of Spades", "King of Spades", "Ace of Spades","2 of Clubs", "3 of Clubs","4 of Clubs", "5 of Clubs", "6 of Clubs", "7 of Clubs", "8 of Clubs", "9 of Clubs", "10 10 of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs", "Ace of Clubs"];
//set card var to array length
card=cardArray.length;
score=0;
//populate it
//uncomment below to trace all members of cardArray
//trace(cardArray.toString());
//function to take random member from cardArray
function selectCard(){
//rand select
card=cardArray.length;
//trace(card);
randCard=random(card);
randMember=cardArray[randCard];
//trace(randMember);
//remove member from cardArray
cardArray.splice(randCard,1);
//uncomment below to trace all members of cardArray
//trace(cardArray.toString());
//call scoreCard function
scoreCard();
}
function scoreCard(){
//get first member of string, check to see if its a number
char=randMember.charAt(0);
char=Number(char);
if(char==NaN){
trace("Hi");
score+=10;
}else //trace(char);
trace("Lo");
score+=char;
//trace(score);
}
check out the attached .fla to see it in action–
the only thing that doesn’t work yet is the score function if statement–what i’m trying to do is check the first char of the string and if it’s a number, add the number to the score, but if it returns ‘NaN’ (not a number) then it will just add 10 to the score–so even tho NaN is defined as a variable in flash, somehow my if statement ‘char==NaN’ isn’t working…
guess we’ll need some help from the rest of the board on this one, eh?
-mojo