Page 1 of 1

designing a peon maker

Posted: Thu May 25, 2006 2:55 pm
by Folcon
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


basically im trying to create a script that makes peons... of both male and female but for some reason i always end up with male peons... (reasons unknow either rand is not working or something is auto switching to male  ) not a great this when i plan to add a later script that allows peons over a certain age to procreate... so any ideas as to what is wrong?

this script is a modular include file so for testing purposes all the variables i can call are listed in the beginning then i will include it in its proper place once i know it works...

Code: Select all

<?
include('DB.php');
ConnectToDB();
function peonborn()
{
$username = "Freddy";
$peonage = 1;
$peonjob = "none";
$peonmoney = 0;
$peonsex = rand(0,1);
if($peonsex = 1)
{$peonsex = "m" ;}
 else { $peonsex = "f" ; }

if($peonsex = "m")
{
$array = file("MaleFirstNames.txt");
shuffle($array);
for ($i=0; $i<1; $i++) {
echo $array[$i];
$PEONSQL = "INSERT into peons(user,name,sex,age,job,money,moneylast,buildingno) VALUES ('$username','$array[$i]', '$peonsex','$peonage','$peonjob','$peonmoney','0','0')";
mysql_query($PEONSQL) or die("could not insert into table peons");
}
}
else
{
$array = file("FemaleFirstNames.txt");
shuffle($array);
for ($i=0; $i<1; $i++) {
echo $array[$i];
$PEONSQL = "INSERT into peons(user,name,sex,age,job,money,moneylast,buildingno) VALUES ('$username','$array[$i]', '$peonsex','$peonage','$peonjob','$peonmoney','0','0')";
mysql_query($PEONSQL) or die("could not insert into table peons");
}
}
}
function insertpeonvalues()
{
$PEONSQL = "INSERT into peons(user,name,sex,age,job,money,moneylast,buildingno) VALUES ('$username','$peonname', '$peonsex','$peonage','$peonjob','$peonmoney','0','0')";
mysql_query($PEONSQL) or die("could not insert into table peons");
}

peonborn();
//insertpeonvalues();

?>
:? :?


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu May 25, 2006 2:57 pm
by Flamie
because in your if's you use = instead of == so it sets them all to male.

Posted: Thu May 25, 2006 3:07 pm
by Folcon
great thanks!!
hmm i assume you mean like this

Code: Select all

if($peonsex == 0)
{$peonsex == "f" ;}
 else { $peonsex == "m" ; }
the only problem that causes is that the variable peonsex doesn't change from numbers to m or f.... hmm i might have to shift the variable or something...

Posted: Thu May 25, 2006 3:12 pm
by Folcon
never mind be being thick it is now

Code: Select all

if($peonsex == 0)
{$peonsex = "f" ;}
 else { $peonsex = "m" ; }
allowing $peonsex to be equated to 0 and then later changing it to either m or f...

thanks for that though :)