Post by .:Desertflower:. on Dec 26, 2006 3:16:23 GMT -5
How about we make the first ever Warriors RPG/Virtual Pet site!
I don't know about you guys but it sounds cool to me. I found this on a board on of of my Virtual Pet Sites:
So, You Want to Create a Sim Game?
Maybe you've been thinking about it for a few days, maybe months, maybe even years. The ideas have been building. You finally have a perfect concept -- a great idea for a sim game that has unique aspects that will set it apart from all the rest, a game that you know people will just love. You may have begun to investigate how to create such a thing. That's when you probably realized just how much work a sim game can be to create. Unfortunately, it's not as simple as thinking up great concepts, although that can be difficult as well. In most cases, implementation is the struggle.
I've had many people send me messages asking me how FP was made, usually because they were interested in creating a sim of their own.
That, in part, is what has prompted this post. I'll be typing up a several part series based on just how to get started on creating your own game -- based on my experiences. I'll also include some mistakes I made and some of the regrets I have in hopes that maybe you can learn from those mistakes, and with any luck, avoid them.
Believe me, I'm no professional. I had no experience when I first started creating FP, but perhaps we have that much in common.
Part I - Genesis
(cuz genesis is a fancy word for beginning)
I first got the idea of creating a sim game somewhere in the year of 2000. At the time, I was a member of Horseland, and loved the challenge and friendships it provided. My first love, though, was dogs, and although I searched the internet for a good dog sim, I couldn't find any that I liked. I began to think that it would be nice to be able to create a dog sim, since none were really around at the time. I did a little preliminary research, saw that heavy programming was involved, got discouraged, and left the topic alone.
Three years later, during the summer of 2003, I had plenty of time on my hands and again got the idea to make a dog sim. So, I dug in again, and didn't give up this time.
I found out that many of the popular pet sites used either PHP or ASP (both scripting languages) for their pages, in conjunction with something called mySQL, which is a database which stores information.
At the time, the extent of my programming knowledge was HTML with a sprinkle of CSS. I didn't know nuthin'.
I went to the library and picked up a book on PHP there. It contained instructions on how to install apache, php, and mySQL on a personal computer for testing purposes. Since I had no idea if FP would ever go live, and this was more of a curiosity for me than anything, I wasn't prepared to fork over a monthly fee to rent part of a server online. Hence, I installed what I needed on my PC instead so that I could test initial phases of the game without having to pay anyone anything. I chose PHP over ASP because I'd heard that ASP required a purchase of some sort, while PHP was completely free. Apache and mySQL are also free, for the record. I'll include some links to installation tutorials for these three things at the bottom of this post.
I slugged away through about three chapters in the PHP book before I got bored. I instead began to google for tutorials on login and registering scripts that involved PHP and mySQL. My idea was simple: if I could figure out how to make a login script work, I could make any page I wanted to, because the commands used to make a login script work are nearly identical to all of the other commands I'd need to create a website. I managed to find a tutorial, and with a lot of struggle and a lot of errors, I finally got the register and login script to work on my desktop.
And so, to put it quite dramatically, Furry Paws was born.
For those of you who are wanting to start up your own sim game, I highly recommend that you install apache/mysql/php on your own machine and get at the very least a rough draft of your website up and running before you subscribe to a hosting service. This is a good thing for several reasons. First and foremost, it's free for you. You won't be getting any server bills when you don't have any donations flowing in, and you won't have to worry about ripping people off who may have paid for "Alpha" accounts if your website never goes live.
Link
Apache/mySQL/PHP Tutorial - I haven't actually used this tutorial, but I glanced over it and it looks like it'll do the trick.
Coming Soon: Part II. I'll post a simple register and login script that you can use to get yourself started. I'll also go over some basic table creation techniques. Finally, I'll cover some common causes for those annoying PHP syntax errors. Be sure to install Apache/mySQL/PHP on your machine in the mean time, and of course, feel free to fiddle around and try to figure things out on your own. The more you do, the faster you learn. Get your feet wet
And Part 2:
Part II - Starting Out
Hopefully, by now, if you're interested in building your own sim game, you installed php, mySQL, and apache on your desktop. If not, www.easyphp.org/ has a wonderful package that will install all three components for you with absolutely no trouble. (Thanks to Ravenfeather for reminding me of it I'll be basing my instructions off of this package.
Again, this isn't really meant to be a step-by-step tutorial as to how you can make your own sim game, but more of a series of observations of how things went for me. I'll be emphasizing parts that had be stuck, too I will not be explaining how to program, or what each line does, it's your job to find that out! The internet is a wonderful resource, I guarentee that there are hundreds of tutorials out there which can tell you how PHP works. And don't forget the PHP website itself! www.php.net is full of documentation and lists every single function PHP has, as well as how to use it
As mentioned before, I decided that my first task in figuring out how to create a fully automated sim game was to make a script that would allow users to register and log in. I found a tutorial on how to do so by searching with Google, but the script was buggy, and I ended up having to debug it to get it to work -- imagine how hard that was when I had no programming experience!
PHP will tell you when there's an obvious script error, however. It will tell you the type of error and the line that it's on.
The most common error you'll probably see looks like this:
Parse error: parse error in c:\program files\easyphp1-8\www\connect.php on line 22
Parse error basically means that you either forgot a character or put a character in the wrong place. In this case, I left a ")" out of an if() statement. If you get this type of error, the best way to go about fixing it is to immediately go check the line it says the error is on. If you can't find anything wrong with that, check the lines immediately above and below it.
Sometimes this error will also pop up showing the line which the error is on as the last line in the script file. When this happens (in my case) it usually meant that I forgot to to close an if-else statement somewhere.
Now then, the following four textboxes contain four basic pages that you can use to get start. Most importantly, perhaps, is the connect.php script. It will connect a player to your database and allow them to interact with your website. It also checks to see whether a player is logged in.
If you want to try these out (and are using the EasyPHP package) copy them to notepad then save them in the following directory: C:\Program Files\EasyPHP1-8\www
Be sure to use the extension .php at the end of each (ie, connect.php NOT connect.html) or PHP won't know to take a look at them
connect.php
<?php
// This script will connect the user to your mySQL database.
// It will also check it they're logged in or not.
// It should be included on every page you create.
// Set the variables below to match your settings
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'mygame';
$link = mysql_pconnect($dbhost, $dbuser, $dbpass)
or die("Could not connect to server.");
$selectdb = mysql_select_db($dbname, $link)
or die("Could not connect to database.");
// Check to see if user is logged in
session_start();
if((!isset($_SESSION['id'])) || (!isset($_SESSION['username'])) ||
(!isset($_SESSION['password'])))
{
unset($_SESSION['username']);
unset($_SESSION['password']);
unset($_SESSION['id']);
$loggedin = 0;
}
else
{
$loggedin = 1;
}
?>
index.php
<?php
include('connect.php');
if($loggedin == '0')
{
if(isset($_POST['submit']))
{
// Make sure all forms were filled out.
if((!isset($_POST['username'])) || (!isset($_POST['pass']))
|| ($_POST['username'] == '') || ($_POST['pass'] == ''))
die("Please fill out the form completely. <br><br>
<a href=index.php>Continue</a>");
// Get user's record from database
$player = @mysql_query("SELECT id, username, password, registered, lastlogin FROM players WHERE username = '".$_POST['username']."'");
$player = @mysql_fetch_assoc($player);
if($player['id'] == false)
die("Sorry, that user is not in our database.<br><br>
<a href=index.php>Back</a>");
else if($player['password'] != md5($_POST['pass']))
die("Wrong password!<br><br>
<a href=index.php>Back</a>");
// set session variables
$_SESSION['id'] = $player['id'];
$_SESSION['username'] = $player['username'];
$_SESSION['password'] = $player['password'];
// update last login
$date = date("m/d/y");
$update = @mysql_query("UPDATE players SET lastlogin = '$date' WHERE id = '".$_SESSION['id']."'");
echo 'You are now logged in!';
}
else
{
echo 'You are not logged in. <br><br>
<form action=index.php method=post>
Username: <input type=text name=username><br>
Password: <input type=password name=pass><br>
<input type=submit name=submit value=Submit>
</form>
Would you like to <a href=register.php>register?</a>';
}
}
else
{
echo 'You are logged in!
Welcome to my game, '.$_SESSION['username'].'!
<br><br>
<a href=logout.php>Click Here to Logout</a>';
}
?>
register.php
<?php
include('connect.php');
if($loggedin == '1')
die("You can't register another account while you're logged in.");
// Register Script
// So, the register script is a sample of the basic elements of
// coding used in a simple sim game, namely, putting new data
// into databases.
if(isset($_POST['submit']))
{
// trim removes the whitespaces from the beginning and end of text
// this keeps someone from having a username of " "
$uname = trim($_POST['username']);
// Make sure all forms were filled out.
if((!isset($_POST['username'])) || (!isset($_POST['pass']))
|| ($uname == '') || ($_POST['pass'] == ''))
die("Please fill out the form completely. <br><br>
<a href=register.php>Continue</a>");
// Make sure name hasn't already been used.
$check = @mysql_query("SELECT id FROM players WHERE username = '$uname'");
$check = @mysql_num_rows($check);
if($check > 0)
die("Sorry, that username has already been taken. Please try again.
<br><br>
<a href=register.php>Continue</a>");
// Encrypt password
$pass = md5($_POST['pass']);
$date = date("m/d/y");
// Finally, create the record.
$newPlayer = @mysql_query("INSERT INTO players (username, password, registered) VALUES ('$uname', '$pass', '$date')") or die("Error: ".mysql_error());
echo 'You have been registered! You may now <a href=index.php>Log in</a>.';
}
else
{
// A simple example of a form.
echo '<form action=register.php method=post>
Username: <input type=text name=username><br>
Password: <input type=password name=pass><br>
<input type=submit name=submit value=Submit>
</form>';
}
?>
logout.php
<?php
include('connect.php');
unset($_SESSION['id']);
unset($_SESSION['username']);
unset($_SESSION['password']);
$_SESSION = array();
@session_destroy();
echo 'You have been logged out. <a href=index.php>Continue</a>';
?>
After saving these files in the specified directory, you should be able to access them by typing "localhost/index.php" or "localhost/register.php" into the address bar of your browser.
I should mention here that before these pages will work, you’ll need to create a few things in mySQL so that it knows where to store the information. You can do this via php script, but I find it easier to use phpMyAdmin, which is included in the easyphp package. To get to phpMyAdmin, assuming you’re using the easyphp package, type the following into the address bar of your browser: http://127.0.0.1/mysql/
Once there, click on the form underneath “Create new database”. Type “mygame” into the space. Once that has been created, click on the form underneath “Create new table on database mygame” and type “players”. “players” will be the name of the table that holds information about your game’s members. For now, go ahead and type “5” in the fields space.
Next, you should be brought to a page which lists a series of five rows. In the field of the first row, type “id”. This field will be how your game differentiates between players. In the “Type” dropdown select int. For the length, type 11. Now, to make sure every player has a unique number (which is *very* important!) scroll over to the right until you see the “Extra” column. Select auto_increment. Now, every time a new row is inserted, it will automatically be assigned a unique id number (that took me forever to figure out ). Be sure to click the radio button beneath the key just to the right of the extra dropdown. This will make it so that the database will have a much easier time locating the record via player number.
The next few fields should be the following:
username varchar 150
password varchar 150
registered varchar 15
lastlogin varchar 15
Next, hit the “Save” button. The table has been created, yay!
The above files are a brief but informative sample of what the pages of your sim game will look like. The programming of a basic sim game is quite simple, although often time consuming. Essentially, every page you produce will be interacting with your databases to form some function. Want a page that displays information about a certain dog? Then you need to write code that will look for that dog in your database and return information about that dog, such as its name, gender, etc. Want to update the dog’s name? Then write a script to find the right dog and change its name.
Now, for a brief discussion on optimization One of the biggest troubles with Furry Paws, right off the bat, is that it was slow when there were too many people on. This is due to two major things. First, that I was inexperienced with programming and my code was very inefficient. Keep this in mind when you’re writing your own pages. Think hard every time you make a query to the database, as that tends to be the largest bottleneck in games like these. Make sure that each field you’re using after your “WHERE” statement has been indexed (will talk more about this next). Make sure that you really NEED another query. If there’s a way to use only one query instead of three, do so. Avoid using the “*” character after SELECT. Instead, list each field you need, and only the fields you need, by name.
The second and worst problem that caused troubles with speed, and still does to this day, is that I very inefficiently set up databases. For mySQL, since sim games tend to do more SELECT statements than INSERT statements, it’s a good rule of thumb to index every field you’re going to be searching by. For example, the index.php script above looks for a user in the player table by the “username” field. You should index this. To do so, go to the players table in mysql and click the lightning bolt icon in the username row. This will add an index to the username field so that mySQL can easily find various users.
Another good way to help a site’s speed is to run the ANALYZE or OPTIMIZE scripts on tables fairly often. This will keep indexes up to date.
Anyway, the four files above contain quite a lot to digest for a new programmer, so take your time! Carefully read through them and try to understand every line. If you haven’t already done so, it may be a good idea to borrow a book from the library on PHP so that you’ll have an easier time understanding what does what. Again, you can also use www.php.net as a resource. Good luck!
Coming Soon: Part III. I’ll talk more about some of the mistakes I made, and some of the changes I wished I’d made early on.
I don't know about you guys but it sounds cool to me. I found this on a board on of of my Virtual Pet Sites:
So, You Want to Create a Sim Game?
Maybe you've been thinking about it for a few days, maybe months, maybe even years. The ideas have been building. You finally have a perfect concept -- a great idea for a sim game that has unique aspects that will set it apart from all the rest, a game that you know people will just love. You may have begun to investigate how to create such a thing. That's when you probably realized just how much work a sim game can be to create. Unfortunately, it's not as simple as thinking up great concepts, although that can be difficult as well. In most cases, implementation is the struggle.
I've had many people send me messages asking me how FP was made, usually because they were interested in creating a sim of their own.
That, in part, is what has prompted this post. I'll be typing up a several part series based on just how to get started on creating your own game -- based on my experiences. I'll also include some mistakes I made and some of the regrets I have in hopes that maybe you can learn from those mistakes, and with any luck, avoid them.
Believe me, I'm no professional. I had no experience when I first started creating FP, but perhaps we have that much in common.
Part I - Genesis
(cuz genesis is a fancy word for beginning)
I first got the idea of creating a sim game somewhere in the year of 2000. At the time, I was a member of Horseland, and loved the challenge and friendships it provided. My first love, though, was dogs, and although I searched the internet for a good dog sim, I couldn't find any that I liked. I began to think that it would be nice to be able to create a dog sim, since none were really around at the time. I did a little preliminary research, saw that heavy programming was involved, got discouraged, and left the topic alone.
Three years later, during the summer of 2003, I had plenty of time on my hands and again got the idea to make a dog sim. So, I dug in again, and didn't give up this time.
I found out that many of the popular pet sites used either PHP or ASP (both scripting languages) for their pages, in conjunction with something called mySQL, which is a database which stores information.
At the time, the extent of my programming knowledge was HTML with a sprinkle of CSS. I didn't know nuthin'.
I went to the library and picked up a book on PHP there. It contained instructions on how to install apache, php, and mySQL on a personal computer for testing purposes. Since I had no idea if FP would ever go live, and this was more of a curiosity for me than anything, I wasn't prepared to fork over a monthly fee to rent part of a server online. Hence, I installed what I needed on my PC instead so that I could test initial phases of the game without having to pay anyone anything. I chose PHP over ASP because I'd heard that ASP required a purchase of some sort, while PHP was completely free. Apache and mySQL are also free, for the record. I'll include some links to installation tutorials for these three things at the bottom of this post.
I slugged away through about three chapters in the PHP book before I got bored. I instead began to google for tutorials on login and registering scripts that involved PHP and mySQL. My idea was simple: if I could figure out how to make a login script work, I could make any page I wanted to, because the commands used to make a login script work are nearly identical to all of the other commands I'd need to create a website. I managed to find a tutorial, and with a lot of struggle and a lot of errors, I finally got the register and login script to work on my desktop.
And so, to put it quite dramatically, Furry Paws was born.
For those of you who are wanting to start up your own sim game, I highly recommend that you install apache/mysql/php on your own machine and get at the very least a rough draft of your website up and running before you subscribe to a hosting service. This is a good thing for several reasons. First and foremost, it's free for you. You won't be getting any server bills when you don't have any donations flowing in, and you won't have to worry about ripping people off who may have paid for "Alpha" accounts if your website never goes live.
Link
Apache/mySQL/PHP Tutorial - I haven't actually used this tutorial, but I glanced over it and it looks like it'll do the trick.
Coming Soon: Part II. I'll post a simple register and login script that you can use to get yourself started. I'll also go over some basic table creation techniques. Finally, I'll cover some common causes for those annoying PHP syntax errors. Be sure to install Apache/mySQL/PHP on your machine in the mean time, and of course, feel free to fiddle around and try to figure things out on your own. The more you do, the faster you learn. Get your feet wet
And Part 2:
Part II - Starting Out
Hopefully, by now, if you're interested in building your own sim game, you installed php, mySQL, and apache on your desktop. If not, www.easyphp.org/ has a wonderful package that will install all three components for you with absolutely no trouble. (Thanks to Ravenfeather for reminding me of it I'll be basing my instructions off of this package.
Again, this isn't really meant to be a step-by-step tutorial as to how you can make your own sim game, but more of a series of observations of how things went for me. I'll be emphasizing parts that had be stuck, too I will not be explaining how to program, or what each line does, it's your job to find that out! The internet is a wonderful resource, I guarentee that there are hundreds of tutorials out there which can tell you how PHP works. And don't forget the PHP website itself! www.php.net is full of documentation and lists every single function PHP has, as well as how to use it
As mentioned before, I decided that my first task in figuring out how to create a fully automated sim game was to make a script that would allow users to register and log in. I found a tutorial on how to do so by searching with Google, but the script was buggy, and I ended up having to debug it to get it to work -- imagine how hard that was when I had no programming experience!
PHP will tell you when there's an obvious script error, however. It will tell you the type of error and the line that it's on.
The most common error you'll probably see looks like this:
Parse error: parse error in c:\program files\easyphp1-8\www\connect.php on line 22
Parse error basically means that you either forgot a character or put a character in the wrong place. In this case, I left a ")" out of an if() statement. If you get this type of error, the best way to go about fixing it is to immediately go check the line it says the error is on. If you can't find anything wrong with that, check the lines immediately above and below it.
Sometimes this error will also pop up showing the line which the error is on as the last line in the script file. When this happens (in my case) it usually meant that I forgot to to close an if-else statement somewhere.
Now then, the following four textboxes contain four basic pages that you can use to get start. Most importantly, perhaps, is the connect.php script. It will connect a player to your database and allow them to interact with your website. It also checks to see whether a player is logged in.
If you want to try these out (and are using the EasyPHP package) copy them to notepad then save them in the following directory: C:\Program Files\EasyPHP1-8\www
Be sure to use the extension .php at the end of each (ie, connect.php NOT connect.html) or PHP won't know to take a look at them
connect.php
<?php
// This script will connect the user to your mySQL database.
// It will also check it they're logged in or not.
// It should be included on every page you create.
// Set the variables below to match your settings
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'mygame';
$link = mysql_pconnect($dbhost, $dbuser, $dbpass)
or die("Could not connect to server.");
$selectdb = mysql_select_db($dbname, $link)
or die("Could not connect to database.");
// Check to see if user is logged in
session_start();
if((!isset($_SESSION['id'])) || (!isset($_SESSION['username'])) ||
(!isset($_SESSION['password'])))
{
unset($_SESSION['username']);
unset($_SESSION['password']);
unset($_SESSION['id']);
$loggedin = 0;
}
else
{
$loggedin = 1;
}
?>
index.php
<?php
include('connect.php');
if($loggedin == '0')
{
if(isset($_POST['submit']))
{
// Make sure all forms were filled out.
if((!isset($_POST['username'])) || (!isset($_POST['pass']))
|| ($_POST['username'] == '') || ($_POST['pass'] == ''))
die("Please fill out the form completely. <br><br>
<a href=index.php>Continue</a>");
// Get user's record from database
$player = @mysql_query("SELECT id, username, password, registered, lastlogin FROM players WHERE username = '".$_POST['username']."'");
$player = @mysql_fetch_assoc($player);
if($player['id'] == false)
die("Sorry, that user is not in our database.<br><br>
<a href=index.php>Back</a>");
else if($player['password'] != md5($_POST['pass']))
die("Wrong password!<br><br>
<a href=index.php>Back</a>");
// set session variables
$_SESSION['id'] = $player['id'];
$_SESSION['username'] = $player['username'];
$_SESSION['password'] = $player['password'];
// update last login
$date = date("m/d/y");
$update = @mysql_query("UPDATE players SET lastlogin = '$date' WHERE id = '".$_SESSION['id']."'");
echo 'You are now logged in!';
}
else
{
echo 'You are not logged in. <br><br>
<form action=index.php method=post>
Username: <input type=text name=username><br>
Password: <input type=password name=pass><br>
<input type=submit name=submit value=Submit>
</form>
Would you like to <a href=register.php>register?</a>';
}
}
else
{
echo 'You are logged in!
Welcome to my game, '.$_SESSION['username'].'!
<br><br>
<a href=logout.php>Click Here to Logout</a>';
}
?>
register.php
<?php
include('connect.php');
if($loggedin == '1')
die("You can't register another account while you're logged in.");
// Register Script
// So, the register script is a sample of the basic elements of
// coding used in a simple sim game, namely, putting new data
// into databases.
if(isset($_POST['submit']))
{
// trim removes the whitespaces from the beginning and end of text
// this keeps someone from having a username of " "
$uname = trim($_POST['username']);
// Make sure all forms were filled out.
if((!isset($_POST['username'])) || (!isset($_POST['pass']))
|| ($uname == '') || ($_POST['pass'] == ''))
die("Please fill out the form completely. <br><br>
<a href=register.php>Continue</a>");
// Make sure name hasn't already been used.
$check = @mysql_query("SELECT id FROM players WHERE username = '$uname'");
$check = @mysql_num_rows($check);
if($check > 0)
die("Sorry, that username has already been taken. Please try again.
<br><br>
<a href=register.php>Continue</a>");
// Encrypt password
$pass = md5($_POST['pass']);
$date = date("m/d/y");
// Finally, create the record.
$newPlayer = @mysql_query("INSERT INTO players (username, password, registered) VALUES ('$uname', '$pass', '$date')") or die("Error: ".mysql_error());
echo 'You have been registered! You may now <a href=index.php>Log in</a>.';
}
else
{
// A simple example of a form.
echo '<form action=register.php method=post>
Username: <input type=text name=username><br>
Password: <input type=password name=pass><br>
<input type=submit name=submit value=Submit>
</form>';
}
?>
logout.php
<?php
include('connect.php');
unset($_SESSION['id']);
unset($_SESSION['username']);
unset($_SESSION['password']);
$_SESSION = array();
@session_destroy();
echo 'You have been logged out. <a href=index.php>Continue</a>';
?>
After saving these files in the specified directory, you should be able to access them by typing "localhost/index.php" or "localhost/register.php" into the address bar of your browser.
I should mention here that before these pages will work, you’ll need to create a few things in mySQL so that it knows where to store the information. You can do this via php script, but I find it easier to use phpMyAdmin, which is included in the easyphp package. To get to phpMyAdmin, assuming you’re using the easyphp package, type the following into the address bar of your browser: http://127.0.0.1/mysql/
Once there, click on the form underneath “Create new database”. Type “mygame” into the space. Once that has been created, click on the form underneath “Create new table on database mygame” and type “players”. “players” will be the name of the table that holds information about your game’s members. For now, go ahead and type “5” in the fields space.
Next, you should be brought to a page which lists a series of five rows. In the field of the first row, type “id”. This field will be how your game differentiates between players. In the “Type” dropdown select int. For the length, type 11. Now, to make sure every player has a unique number (which is *very* important!) scroll over to the right until you see the “Extra” column. Select auto_increment. Now, every time a new row is inserted, it will automatically be assigned a unique id number (that took me forever to figure out ). Be sure to click the radio button beneath the key just to the right of the extra dropdown. This will make it so that the database will have a much easier time locating the record via player number.
The next few fields should be the following:
username varchar 150
password varchar 150
registered varchar 15
lastlogin varchar 15
Next, hit the “Save” button. The table has been created, yay!
The above files are a brief but informative sample of what the pages of your sim game will look like. The programming of a basic sim game is quite simple, although often time consuming. Essentially, every page you produce will be interacting with your databases to form some function. Want a page that displays information about a certain dog? Then you need to write code that will look for that dog in your database and return information about that dog, such as its name, gender, etc. Want to update the dog’s name? Then write a script to find the right dog and change its name.
Now, for a brief discussion on optimization One of the biggest troubles with Furry Paws, right off the bat, is that it was slow when there were too many people on. This is due to two major things. First, that I was inexperienced with programming and my code was very inefficient. Keep this in mind when you’re writing your own pages. Think hard every time you make a query to the database, as that tends to be the largest bottleneck in games like these. Make sure that each field you’re using after your “WHERE” statement has been indexed (will talk more about this next). Make sure that you really NEED another query. If there’s a way to use only one query instead of three, do so. Avoid using the “*” character after SELECT. Instead, list each field you need, and only the fields you need, by name.
The second and worst problem that caused troubles with speed, and still does to this day, is that I very inefficiently set up databases. For mySQL, since sim games tend to do more SELECT statements than INSERT statements, it’s a good rule of thumb to index every field you’re going to be searching by. For example, the index.php script above looks for a user in the player table by the “username” field. You should index this. To do so, go to the players table in mysql and click the lightning bolt icon in the username row. This will add an index to the username field so that mySQL can easily find various users.
Another good way to help a site’s speed is to run the ANALYZE or OPTIMIZE scripts on tables fairly often. This will keep indexes up to date.
Anyway, the four files above contain quite a lot to digest for a new programmer, so take your time! Carefully read through them and try to understand every line. If you haven’t already done so, it may be a good idea to borrow a book from the library on PHP so that you’ll have an easier time understanding what does what. Again, you can also use www.php.net as a resource. Good luck!
Coming Soon: Part III. I’ll talk more about some of the mistakes I made, and some of the changes I wished I’d made early on.