-
Website
http://buildingbrowsergames.com -
Original page
http://buildingbrowsergames.com/2008/05/05/designing-browsergames-a-flexible-stats-system/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
gabrielbianconi
1 comment · 1 points
-
Luke
82 comments · 1 points
-
spatlabor
1 comment · 1 points
-
HughCompton
2 comments · 1 points
-
obat jerawat
1 comment · 1 points
-
-
Popular Threads
If you want to have some stats that are numeric and some that are text based there are several possible approaches.
One would be to replace the value field with two fields one numeric that other text...and have a third Enum typed field to indicate which of those contains the value.
Another aproach would be too have two seperate tables one for text based stats and the other for numeric stats.
although im not convinced for the need for text based stats...theyre not really stats...theyre..ummm...something else? :)
I am not quite sure I understand what the benefit of using the two different types of columns would be - especially in a loosely typed language like Perl or PHP. Whether the user retrieves a number or a word, that value will still be loosely-typed after it's been retrieved - which means the issue can bite the user either way. How would changing the number of columns in the tables fix that?
keep it up
I tend to select all data from the user in my header using a mysql_fetch_array so I can use things like $user['credits'] or $user['id'] wherever I want. Is this a bad habit? I figured you were gonna use the user data on almost every page anyway.
from your user table will be faster - however, if you ever want to add(or
remove) a stat you will need to make changes directly to your user table.
3 tables, users, stats, user_stats (to use the example tables)
I want to grab the stat "Attack" for the user with ID 1.
Attack's ID = 1, User ID = 1. SO
SELECT `user_stats`.`value` FROM `user_stats`,`stats`,`users` WHERE `user_stats`.`userid` = `users`.`id` AND `user_stats`.`statid` = `stats`.`id` WHERE `users`.`id`=1 AND `stats`.`id`=1 LIMIT 1;
And there you have it.
To eliminate the need for querying 3 tables, use a select statement similar to what Anubis has pointed out, but simply create a new view of the 3 tables with it and then query that view.
ie:
create view user_stats_view
as
SELECT * FROM `users`, `stats`, `user_stats`
WHERE `user_stats`.`userid` = `users`.`id` AND `user_stats`.`statid` = `stats`.`id`;