|
Hol Alexander
Registered User
Join date: 16 Mar 2005
Posts: 17
|
12-07-2005 08:47
I have been trying to make a simple higher lower game. For some reason if higher is picked the player always wins and if lower is picked they always lose (even if they picked wrong). I'll be darned if I can find my mistake. key playerID; integer amountPaid; integer winningAmount; integer MaxBet = 100; integer CardValue1; integer CardValue2; integer HIGHER; integer CHANNEL = 987; // dialog channel integer Card = 0; //default card number list High_Low = ["Higher", "Lower"]; // dialog choices
deal_card1() { Card = Card + 1; llMessageLinked(3, 0, "Card 1", ""); }
deal_card2() { //Card = Card + 1; llMessageLinked(2, 0, "Card 2", ""); }
Compare1n2() { if (CardValue1 <= CardValue2) HIGHER = 1; else HIGHER = 0; }
default { state_entry() { //Do some initialization here llRequestPermissions(llGetOwner(), PERMISSION_DEBIT); } run_time_permissions(integer permissions) { //Only wait for payment if the owner agreed to pay out money if (permissions) { llSay(0, "Initailized Successfully..."); state waiting; } } }
state waiting { state_entry() { llSay(0, "Idle..."); } money(key id, integer amount) { playerID = id; amountPaid = amount; if (amountPaid <= MaxBet) { state playing; } else { llSay(0, "This machine has a maximum bet of" + (string)MaxBet); llGiveMoney(playerID, amountPaid); state waiting; } } }
state playing { state_entry() { //Show first card Card = 0; HIGHER = 0; deal_card1(); llListen(CHANNEL, "", playerID, ""); // listen for dialog answers } listen(integer channel, string name, key id, string message) { if (llListFindList(High_Low, [message]) != -1) // verify dialog choice { if (message == "Higher") state Higher; else state Lower; } } //get card value link_message(integer sender_num, integer num, string str, key id) { if ((sender_num = 3) && (str == "Card One")) { CardValue1 = num; llDialog(playerID, "Will the next card be Higer or Lower?", High_Low, CHANNEL); } else if ((sender_num = 3) && (str == "Card Two")) { CardValue2 = num; } }
}
state Higher { state_entry() { deal_card2(); Compare1n2(); if (HIGHER = 1) state winner; else state loser; } }
state Lower { state_entry() { deal_card2(); Compare1n2(); if (HIGHER = 0) state winner; else state loser; } }
state winner { state_entry() { winningAmount = 2 * amountPaid; llSay(0, "You won L$" + (string)winningAmount + "!"); llGiveMoney(playerID, winningAmount); Card = 0; state waiting; } }
state loser { state_entry() { llSay(0, "Sorry, you lose."); Card = 0; state waiting; } }
|
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
12-07-2005 08:52
Your problem is here: From: Hol Alexander state Higher { state_entry() { deal_card2(); Compare1n2(); if (HIGHER = 1) state winner; else state loser; } }
state Lower { state_entry() { deal_card2(); Compare1n2(); if (HIGHER = 0) state winner; else state loser; } }
In your conditional (if) statements, you are trying to compare HIGHER to 1 and HIGHER to 0 respectively - the problem is that you're using the assignment (=) operator instead of the equality (==) operator. Replace = with == in your if statements and try it again. ==Chris
|
|
Gabe Lippmann
"Phone's ringing, Dude."
Join date: 14 Jun 2004
Posts: 4,219
|
12-07-2005 09:05
Oh, technical issue....I thought you hurt your neck at a Pantera concert or something 
_____________________
go to Nocturnal Threads 
|
|
Hol Alexander
Registered User
Join date: 16 Mar 2005
Posts: 17
|
12-07-2005 09:28
From: Christopher Omega Your problem is here: In your conditional (if) statements, you are trying to compare HIGHER to 1 and HIGHER to 0 respectively - the problem is that you're using the assignment (=) operator instead of the equality (==) operator. Replace = with == in your if statements and try it again. ==Chris Thanks so much Christopher that got 90% of the problem. I suspect the other 10% where it is not evaluating correctly is in the card script. Time to go bang my head again for awhile see if I can find it LOL
|
|
Hol Alexander
Registered User
Join date: 16 Mar 2005
Posts: 17
|
12-07-2005 09:28
From: Gabe Lippmann Oh, technical issue....I thought you hurt your neck at a Pantera concert or something  make it AC/DC and maybe we talking 
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
12-07-2005 09:32
Also, what are the odds on a game like this? I was never very good at probability calculations  But if the user were picking completely randomly (i.e. without looking at the first card drawn), they'd be right 50% of the time. Your payout is 2x the bet amount, so on average, this game will make zero dollars if the player were making random guesses. In reality, if the first card is anything other than 7, the player's chances of being correct are better than 50%, so on average, this game will lose money. I understand that this was probably a simple exercise in scripting and not meant to be a real money making game, but I thought I'd point that out anyway. To make this a viable script, you'll have to do some math on the odds, and adjust the payout accordingly. Or maybe my math is wrong, and then someone please correct me 
|
|
Hol Alexander
Registered User
Join date: 16 Mar 2005
Posts: 17
|
12-07-2005 09:56
From: Ziggy Puff Also, what are the odds on a game like this? I was never very good at probability calculations  But if the user were picking completely randomly (i.e. without looking at the first card drawn), they'd be right 50% of the time. Your payout is 2x the bet amount, so on average, this game will make zero dollars if the player were making random guesses. In reality, if the first card is anything other than 7, the player's chances of being correct are better than 50%, so on average, this game will lose money. I understand that this was probably a simple exercise in scripting and not meant to be a real money making game, but I thought I'd point that out anyway. To make this a viable script, you'll have to do some math on the odds, and adjust the payout accordingly. Or maybe my math is wrong, and then someone please correct me  nope your math is right. And you are right in this form this is never intended to a viable game. My way of learning a bit more about LSL and taking baby steps towards a much larger project I want to do 
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
12-07-2005 09:58
OK  Just thought I'd check in case there was real money riding on this  I've done projects where I've had to explain to my customer why his/her game idea would lose money.
|