Five Useful Thoughts while Programming your Game

While programming my online game, Forgotten Creatures, I made many mistakes, some careless, some not. Most of these were small, and easy fixable, but had great impact on the game. It is important to look for these mistakes before you implement a program into your game. In this section I will discuss a few of these and what you should try to look for.




1) Currency Issues A. Negative Money (deposits, transactions, and purchases) It is very important to make sure you watch out for these little bugs. In many programs I have forgot to write a simple line of code which tells the system to make sure the amount of an item they interact with is not a negative number. Incase you do not know here is basically what I use:

if ($user[money] > 0) {
} else {
    echo "Error....";

Some common places I have found this to be a problem is in a bank system, and market places. If you have an option to transfer something into someone’s account make sure you cannot transfer negative of that item. If you can it will take away the other player’s item and give it to the user making the transaction. These mistakes can lead to inflation of your game economy. Always watch for this, and you should have a well-run game.

B. Item Prices
Another thing I noticed while working on my game was setting up a game economy can be very difficult. You must visualize what you want in your game and make it happen. Think about how much money you want the average user to have, and then set the item prices. A great way to do this is playing your game yourself. See how much money you can get and then think about a fair price for an item. This can be a very difficult process but it is vital and necessary.

2) Security
A) Login and Signup
So you think you have the perfect login and signup scripts? Think again. You may have forgotten some things that decrease your games security. These are not difficult things to notice, but you may have slipped up programming at 2am and missed it. Here are some things I slipped up on.
I) Multiple User Protection
Make sure you check for the email, make sure it is not a duplicate.
2) Activity
It’s always a good idea to send a validation code/link to the user’s email just to make sure it is valid.

These are just some thoughts I have on the security of your login and signup. I’m sure there are much more.

3) User Interactivity
This is basically a suggestion. You should make things to do in the game, which are interactive to the user; especially if your game is text-based. Try to make sure a user can occupy themselves for 30 minutes or more. A user will get bored if they run out of things to do. If they do the same things every day and there are not any other objectives in the game they may stop playing the game. Try to update frequently, and provide interactivity.

4) Excellent Management
Every game needs management. You will always find those people who try to cheat, lie and spam people in your game. No body likes these people, but lets face it; we cannot stop it. To protect your game you will need management who are on at all times with their ears open. It is important your members respect these administrators, or they may get sick of the job. Don’t just pick your friends, try to find loyal, active members and reward them with these powers.

5) Patience
Patience……..Patience, patience, patience. A key role in programming your game. Things may go wrong and some things may go right. You should never give up unless you cannot run the game because of financial problems, or just problems in your life. Yep, I admit it; Many things go wrong! Your game may seem like its going well, then all your players may leave. Just remember that hard work will get good results. Keep working and eventually, things will go your way.


Turn Countdowns

In many online games, turns are the source of all income, and actions. You must have turns to do anything at all. So if this is how you are programming your game, you will need a script to count down your turns. This tutorial will cover a basic program that counts down the dealing of turns (assuming 1 turn is given every hour).

Before we do anything we need to create 10 images, one for each number 0-9.

Next we have to find out how to define a variable which tells the system what minute it currently is.
$minute = date(“i”);

The “i” in the date functions represents the current minute with double digits.
Now what? We need to develop an equation, which find out how many minutes until the next hour is up.
$left = 60 – $minute;

Because there are 60 minutes in an hour, if we subtract 60 from the current minute then we find out how many minutes are left. Simple math.

Now what if the variable comes out to be a double-digit number. IE 25, 39, 51. Since we don’t have images for every number between 0 and 60 we need to find a way to split up this number, into 2 different one-digit numbers. We can easily do this with the substr function. This function returns a certain part of a string, defined by you.

$d1 = substr(“$left”, 0, 1); \\ Takes the first digit in a string (represented by “0”), and only takes a total of 1 values
$d2 = substr(“$left”, 1, 1); \\ Takes the second digit in a string (represented by “1”), and only takes a total of 1 values

Why does “0” find the first portion of the string? It’s because all values in PHP start with “0” and work on up, not at one.

Now we are at our last portion of the script. We have the two values for the images that need to be shown. Now we need to show the images. I added some security to the script to make it more efficient.

if ($d1 == “0”) {} // If the first number is “0” it doesn’t show an image, this is just my preference, it can be removed
else {echo “<img src=$d1.gif>”;}
if ($d2) {echo “<img src=$d2.gif>”;} // $d2 will not always be set, it will only be set when there is 10 or more minutes left until the end of the hour
else {}

Here is the whole program:
$minute = date(“i”);
$string = 60 – $minute;
$d1 = substr(“$string”, 0, 1);
$d2 = substr(“$string”, 1, 1);
if ($d1 == “0”) {}
else {echo “<img src=$d1.gif>”;}
if ($d2) {echo “<img src=$d2.gif>”;}
else {}

Well that’s it, everything here can be customized to your preference. You can change hours to minutes if you like. This is just a basic tutorial to help you along your way