Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

hmm a thinker

Harminoff Hadlee
Registered User
Join date: 13 Jul 2004
Posts: 35
08-14-2004 15:39
ok i have to lists for this card game.

one with numbers (ace,1-10,jack,queen,king)

and the other with the card type.

i need to see if the players number is higher then the pc generated one, so i call random and make them new variables like card and pcard number and pnumber. (p) for player.


i need to see if pnumber > number

llsay(0,"you win";);

but the letters only allow =. i tried setting ace=1; jack=11; and so on as global variebles but it didnt do it.


any other ideas? gah im a messy programmer, soory if its hard to understand. just ask if it is
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
08-14-2004 16:02
I suggest that you store all the "cards" as integers and use the integer as an index into a list of strings when you need to name them for output (eg, llSay(0, "you have a " + llList2String(cardNames, cardNumber)); )

Comparisons are then simple; your code doesn't want to deal in names, but your players do.
Harminoff Hadlee
Registered User
Join date: 13 Jul 2004
Posts: 35
08-14-2004 16:12
yes i have that done. but sence in the number list i have the 3 words, it doesnt work properly to see if player got a higher card.
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
08-14-2004 18:48
M'kay. Simple enough - let's assume the variable you use is either an integer for 1-10 or a string for ace, jack, queen, or king. Frankly I think you should just use integer values based on card rank (J=11,Q=12,K=13,A=14), but since you want to bastardize it, more power to you. :p

So, let's have it look something like this as a script example:

CODE

integer cardValue = (integer)(llFrand(13.999) + 1); //get a random card value between 1 and 14.
//Most people use multipliers instead of float values...
//I just use truncation :p

string card = (string)cardValue; //stringifies the card numero
if(card == "11") card = "jack";
else if(card == "12") card = "queen";
else if(card == "13") card = "king";
else if(card == "14") card = "ace";
//pretty self-explanatory. Remember string comparisons
//are easy!

...

Repeat the same process for the computer player's/other players' card(s)...

...

//Here's where I point out that the first response
//would have made this process far easier, but...
//you wanted it your way. :D

//Let's assume the computer's card is stored as
//string computerCard, same process...
//Begin lots and lots and LOTS of arguments
//since we're doing this your way.
if(computerCard == card) llSay(0,"Tie draw");
//Same card equals a tie.
else if(computerCard == "ace" && card != "ace") llSay(0,"You lose");
//Ace is the highest card, so if the CPU has it and you don't?
//You lose :p
else if(computerCard == "king" && (card != "ace" && card != "king") llSay(0,"You lose");
//Same proceedure...
else if(computerCard == "queen" && (card != "ace" && card != "king" && card != "queen") llSay(0,"You lose");
else if(computerCard == "jack" && (card!= "jack" && card != "ace" && card != "king" && card != "queen") llSay(0,"You lose");
else if(llStringLength(card) < 3 && llStringLength(computerCard < 3))
{
if((integer)computerCard > (integer)card llSay(0,"You Lose");
else if((integer)computerCard == (integer)card llSay(0,"Tie game");
else llSay(0,"You Win");
}
else llSay(0,"You Win");
llSay(0,"Your card was a " + card + " and the computer's was a " + computerCard);


A bit much, isn't it? Now, let me show you how it's supposed to look. :D

CODE
nteger cardValue = (integer)(llFrand(13.999) + 1); //get a random card value between 1 and 14.
nteger computerValue = (integer)(llFrand(13.999) + 1); //get a random card value between 1 and 14.
if(computerValue > cardValue) llSay(0,"You Lose");
if(computerValue == cardValue) llSay(0,"Tie Game");
if(computerValue < cardValue) llSay(0,"You Win");
string computer;
string card;
if(computerValue == 11) computer = "jack";
else if(computerValue == 12) computer = "queen";
else if(computerValue == 13) computer = "king";
else if(computerValue == 14) computer = "ace";
else computer = (string)computerValue;
if(cardValue == 11) card = "jack";
else if(card == 12) card = "queen";
else if(cardValue == 13) card = "king";
else if(cardValue == 14) cardr = "ace";
else card = (string)cardValue;
llSay(0,"Your card was a " + card + " and the computer's was a " + computer);


Tell me which one you would prefer seeing in your item, and which would probably run quicker? I could make the process even faster and optimized for multiple players, but for now, this is a simple (enough) example. :D

Now, would someone do me a favor and bring Bridge to SL? I have a hankering to try my hand at it, and I'm sure it'd be awesome for the community. :)