My team is planning to create a simulation game using Javascript, CodeIgniter and MySQL for the backend.
It will be mostly click based, ie: There will be buttons for activities like Eat, Play, Study, etc, and in the game environment, one day will contain 3 phases, day, noon, night . And for each phase, users can pick between those activities and those activities will increase certain character parameters (Intelligence, Focus, Fun, etc) then the game will progress to the next phase. Once it’s night, the game will progress to the next day.
So I need feedbacks on how to saving the game progress. Here’s what I had in mind :
-
There will be a table for Users (obviously) that will contain users’ data including the parameters/stats, money, etc. Do you think the stats etc must be separated to another table so there will be a history of stat increases?
-
For the saving, I’m thinking of using a Logs table that record every activity is by users. So if in day 1 phase 1 (phase day) the user picks Eat, I will insert to this logs table more or less like : user_id = 1, day = 1, phase = 1, activity = eat. So for example when the user stops playing and exits the game after day 1 phase night, the database will have :
user_id = 1, day = 1, phase = 1, activity = eat user_id = 1, day = 1, phase = 2, activity = play user_id = 1, day = 1, phase = 3, activity = sleepAnd when they continue the game, I will read from this table and get the latest row of this user_id, and after checking that the latest row is day 1 phase 3, the game interface will display day 2 phase 1. However, this means that the phases for a day must be fixed from the start, so I can’t include, for example, random additional time phases outside these phases (think of it as an extra opportunity to increase the stats).
So what do you think? I hope the explanation is clear enough.
I think you are on the right track. I do not see why you can’t store the money stats inside the user table, unless you want to keep track of this for the user’s history or progress…
But as a programmer you always want to think ahead, are you going to use these stats in the future? For game perks etc… So it maybe valuable data it may not be… But MySQL can handle billions of records… so I wouldn’t worry about pushing the limits of MySQL… because if you do then your game is already very successful.
If it were me I would setup a second table and xref them for the game actions. If you have a specific things to track you may want to use separate tables for that also … or you may not… those choices are depending on the way the game is to be play &/or developed.
For an online game I would also consider looking into using MySQL’s stored procedures (MySQL 5+)… this is very easy to figure out… its a function which can store logic (if statements etc) & storing SQL inside of mysql server and call these functions from your php mysql query like a normal sql statement… This would allow you to run more than one SQL statement at once… IE. Update, select delete… in one function… etc… This I would imagine would be very useful for game development.
If you look on this Google Search: It is currently the forth document down with a title of MySQL Stored Procedures this is a very good guide on stored procedures it helped me get started… and it was a breeze to do.. I tried to find the direct link on MySQL’s site but its been a while so I’m not sure where its located now.
Good luck on your project.