Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save game-progress in a MySQL database

Tags:

mysql

I am developing a website that is a kind of game. The users' progress is saved in a MySQL-database.

I want to go about this by having a table saves with a column save (ID) and a column progress, where progress is of datatype text. When the user starts out, progress is set to (e.g.) '0'. If he proceeds to level 1, progress is set to '0#1', level two makes it '0#1#2'. The order of levels is free and I want to save it. So progress could be '0#4#2#15' and so on.

Is this a good way to do this? I have no experience with SQL and I don't want to do something incredibly stupid. I've read so much confusing info about tables, foreign keys and whatnot...

I want to thank you for your time reading this and I'm looking forward to answers.

Ryan

like image 315
Ryan Avatar asked Apr 17 '12 13:04

Ryan


People also ask

How do I save in MySQL?

The statements entered can be saved to a file or snippet for later use. At any point, you can also execute the statements you have entered. To save a snippet of code entered into the query editor, click Save SQL to Snippets List ( ) from the SQL query toolbar, enter a name (optional), and click OK.


1 Answers

Answer to your Question 1

I would not approach your problem this way. I would create 3 tables: a Levels table (primary key of 'levelKey'), a Users table (primary key of 'userKey') and a User_Levels table with a composite key of 'levelKey' and 'userKey'. When a user completes a level, just insert into the User_Levels table. Then to see if a user has completed a level is a simple select:

SELECT 'a' FROM User_Levels WHERE userKey = ? AND levelKey = ?

If the number of rows is > 0, the user has completed the level

like image 138
Jeff Lambert Avatar answered Oct 27 '22 13:10

Jeff Lambert