PHP - browser game

stef van de ven

New Member
Messages
9
Reaction score
0
Points
0
Hi all,

I am developing a browser game, this forces me to use PHP.
Because this is my first attempt to develop a game like that, I face some problems. One problem I face is that I really don't know where to put variables.

What do I mean with variables?
For example, you have a town hall and that is the middle point of your empire.
You start with a town hall level 1, maximal inhabitants of 200.
Eventually your amount of inhabitants will reach the 200 limit, to get more inhabitants you need a bigger city, a higher level of town hall. A level 2 townhall costs 500 wood.

In this text above you see a few variables;
- town hall level
- maximal inhabitants
- building costs

In the future more buildings will be released to supply for wood for example.
These variables have to be saved somewhere, that's for sure, but I don't know where and how to do that.

So,
Where do I have to save these variables? (database? / a .php file?)
How to create such files, what kind of codes do I need?
Are there any examples I can use?
Do you know a website or a book I can use for resources?

Thanks for your time!
Stef
 

mindstorm8191

New Member
Messages
24
Reaction score
1
Points
3
When you learn how to use databases, you will find that they are powerful tools to manage your data. I, too, am creating a browser-based game. So far I have stored all the game's related data in the database, and haven't run across any problems in doing so. I can access any specific data whenever I need it, and modify the data whenever necessary.

There are many database engines; I know x10hosting supports mysql, and perhaps one or two more. But from a database user's standpoint the engine doesn't matter until you start using special features. To learn what you need to know about using them, Google should provide you with many different tutorials, and you can search for specific topics / subjects / commands as you need.

Don't worry so much about interfacing with a database from PHP. At least with MySQL, running any database command is handled via one command from PHP, where you can select data from records, insert, update or delete any record as you wish. Reading data from a select command is somewhat simple, too, though there are several options. I usually do a select * from a table, and then use mysql_fetch_assoc(), passing the result of the query command. the result is a list-array (sorry I don't know my php data types that well) where you can use, for example, $player['wood'], to get the amount of wood for that given record.

If that doesn't make much sense, read some tutorials and it may start clicking for you. Good luck.
 

garrettroyce

Community Support
Community Support
Messages
5,611
Reaction score
249
Points
63
Right now, it sounds like you're trying to build a level 40 town hall with only 10 wood ;)

All joking aside, you're getting into a very very complicated scenario and you don't have all the tools you need to do it yet. I would start with some beginner's tutorials and work your way up. You should also know that PHP doesn't do very well with anything graphical. I think you're working your way towards more of a Java type program. There are many good PHP text only games, but I thought I'd mention this :)

You won't have your game done by the end of the week, month, or probably even year. But if you're patient and work hard, you can be an excellent programmer before you know it! :biggrin:
 

stef van de ven

New Member
Messages
9
Reaction score
0
Points
0
I already have a database for members, and I have a login script working with sessions. So PHP and mysql wont be a big problem, and like many people say, there is always something called: 'Google'.

I wanted to know where to store the variables and now I know that I have to store it into the database.

I think I know what to do, and if not, I'll come back here ;)

Thanks all!
 
Top