|
-
Oct 14th, 2007, 09:36 PM
#1
Thread Starter
Junior Member
[RESOLVED] Random Numbers
I'm pulling my hair, I'm just creating a bunch of different little experiments and little fun projects right now. I've got a Deal or No Deal thing that's going very well. I'm trying to create some XML/PHP dealies. And my last one is the where I hit a snag. I'm trying to create a Black Jack game, but my random number generator doesn't seem to be working right. Here's my code: {it's completely unfinished and I only started creating it.}
PHP Code:
session_start();
if(!isset($_SESSION['suite'])){
$_SESSION['suite'] = array("Hearts", "Diamonds", "Clubs","Spades");
}
if(!isset($_SESSION['number']))
{
$_SESSION['number'] = array("Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace");
}
if(!isset($_SESSION['cards']))
{
$_SESSION['cards'];
}
function showCard()
{
$suite = $_SESSION['suite'][rand(0, 3)];
$number = $_SESSION['number'] [rand(0, 12)];
return $number .' of '. $suite;
}
function addToCardsArray($card){
$_SESSION['cards'][] = $card;
}
echo '<form action="mypage.php">';
echo showCard() .'<br>';
echo showCard();
echo '</form>';
The reason I say it doesn't work is that everytime I refresh my page, it returns the same card. Every once in a while it changes, but that happens after a minute or so, so it's not helpful at all.
Last edited by Ataru Moroboshi; Oct 15th, 2007 at 04:50 PM.
-
Oct 14th, 2007, 11:04 PM
#2
Re: Random Numbers
Indent your code, then we'll talk.
-
Oct 15th, 2007, 01:01 AM
#3
Thread Starter
Junior Member
Re: Random Numbers
Hopefully that's indented better.
-
Oct 15th, 2007, 04:25 PM
#4
Re: Random Numbers
well for 1, this isnt doing anything:
PHP Code:
if(!isset($_SESSION['cards']))
{
$_SESSION['cards'];
}
or this:
PHP Code:
function addToCardsArray($card){
$_SESSION['cards'][] = $card;
}
EDIT:
I tested your code, and it works just fine...
http://www.subsoft.net/vbf/card.php
Last edited by dclamp; Oct 15th, 2007 at 04:36 PM.
My usual boring signature: Something
-
Oct 15th, 2007, 04:38 PM
#5
Thread Starter
Junior Member
Re: Random Numbers
Cards is going to be a Session variable that keeps which cards have been played, so if a card is on the list, then a function would get a new card.
-
Oct 15th, 2007, 04:39 PM
#6
Re: Random Numbers
well the top one still doesnt do anything. and did you see my link?
My usual boring signature: Something
-
Oct 15th, 2007, 04:46 PM
#7
Thread Starter
Junior Member
Re: Random Numbers
Yep, I saw it. I added a submit button to the page. That should refresh the page when I press it. I'm going to see if that works.
That function:
Code:
function addToCardsArray($card)
{
$_SESSION['cards'][] = $card;
}
is supposedly to take a value and add the value onto the SESSION array. So it goes from 0 values to 1 value and so on. At least that's what I'm hoping.
Edit: The post and submit button work. It gets new values. Good idea, I was hoping that just simply refreshing the page would work, but apparently not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|