Jump to content


Photo

Help in finding whats wrong in my code


  • Please log in to reply
3 replies to this topic

#1 bprof

bprof
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 04 June 2006 - 04:46 PM

Hi,

I have a problem in this code I don't know why?


function shufelmycards() {
        // we have to use some random stuff here.
        for ($i = 0; $i < 5; $i++) {
        $num = rand(1000,9999);
        mt_srand ((double) microtime() * 9999999);
        $allcards = mt_rand (0,35);
        do {
            mt_srand ((double) microtime() * 9999999);
            $allcards = mt_rand (0,35);
        } while (in_array($allcards,$mycards));
        array_push($mycards,$allcards);
        $oponentcards[$i] = $allcards;
        }
    }

Each time I call this function I get this error message:

in_array(): Wrong datatype for second argument in

array_push(): First argument should be an array in

I've already declared both arrays(mycards, allcards array) early in the script

$mycards = array ();

$oponentcards = array ();


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 04 June 2006 - 05:38 PM

Did you create the mycards variable outside of the function? If you did you need to add the following bit of code after you define your function:
function shufelmycards() {
    global $mycards; // add this line!

Now your function will be able to access the $mycards variable.

Variables dont have global scope when being used inside a function. In order for your variables to be accessable from the function you need to declare them as global.

#3 bprof

bprof
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 05 June 2006 - 06:44 AM

[!--quoteo(post=379964:date=Jun 4 2006, 12:38 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 4 2006, 12:38 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Did you create the mycards variable outside of the function? If you did you need to add the following bit of code after you define your function:
function shufelmycards() {
    global $mycards; // add this line!

Now your function will be able to access the $mycards variable.

Variables dont have global scope when being used inside a function. In order for your variables to be accessable from the function you need to declare them as global.
[/quote]

Thanks alot for your help. I cant see what I want, but I can see something :) thanks alot.

Could you please help me find out why I can see what I want which is (Oppenents cards 4 covered, on uncover. Player cards 5 uncovered):

$allcards = array(
"cards/6_hearts.gif" , "cards/7_hearts.gif" , "cards/8_hearts.gif" , "cards/9_hearts.gif" , "cards/10_hearts.gif" , "cards/11_hearts.gif" , "cards/12_hearts.gif" , "cards/13_hearts.gif" , "cards/14_hearts.gif" ,
"cards/6_spades.gif" , "cards/7_spades.gif" , "cards/8_spades.gif" , "cards/9_spades.gif" , "cards/10_spades.gif" , "cards/11_spades.gif" , "cards/12_spades.gif" , "cards/13_spades.gif" , "cards/14_spades.gif" ,
"cards/6_diamonds.gif" , "cards/7_diamonds.gif" , "cards/8_diamonds.gif" , "cards/9_diamonds.gif" , "cards/10_diamonds.gif" , "cards/10_diamonds.gif" , "cards/11_diamonds.gif" , "cards/12_diamonds.gif" , "cards/13_diamonds.gif" , "cards/14_diamonds.gif" ,
"cards/6_clubs.gif" , "cards/7_clubs.gif" , "cards/8_clubs.gif" , "cards/9_clubs.gif" , "cards/10_clubs.gif" , "cards/11_clubs.gif" , "cards/12_clubs.gif" , "cards/13_clubs.gif" , "cards/14_clubs.gif");

$values = array(
"6" , "7" , "8" , "9" , "10" , "11" , "12" , "13" , "14" ,
"6" , "7" , "8" , "9" , "10" , "11" , "12" , "13" , "14" ,
"6" , "7" , "8" , "9" , "10" , "11" , "12" , "13" , "14" ,
"6" , "7" , "8" , "9" , "10" , "11" , "12" , "13" , "14" );

function showcards($show,$title,$footer) {
        global $allcards;
        global $useraction;
        $showcards .= "<table width='70%' background='gfx/black.gif' cellspacing='   2' cellpadding='0' border='0'>
<tr><td valign='top'><TABLE width='100%' cellspacing='0' cellpadding='5' border='0'><TR><TD align='center' bgcolor='#000066'><img src=\"gfx/$title.gif\" alt='' border='0' align='top'></td></tr></table></td></tr>
<tr><td valign='top'><TABLE width='100%' cellspacing='0' cellpadding='5' border='0'><TR><TD align='center' bgcolor='#0066ff'>";
        for($i=0; $i < sizeof($show); $i++) {
        $card = $show[$i];
        if ($useraction != "deal" && $title == "dealershand" && $i == 0) {
            $showcards .= "<img src='cards/back.gif' width='71' height='96' alt='' border='0'>&nbsp;";
        } else {
            $showcards .= "<img src=" . $allcards[$card] . " width='71' height='96' alt='' border='0'>&nbsp;";
        }
    }
    $showcards .= "<br>$footer</td></tr></table></td></tr></table><br>";
    return $showcards;
}


#4 bprof

bprof
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 05 June 2006 - 04:06 PM

Any help please???




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users