Bank Tutorial

Post all your tuts or request for tuts here.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Bank Tutorial

Post by Jackolantern »

jpoisson wrote:I guess you don't have to do the transfer of items from on table to another but it is a lot more flexible then by just adding a new field.
Adding a new field would also likely increase the size of the db needlessly compared to putting them in a new table. If the original tables are well organized, then an inventory or bank table would likely just be a simple one-to-many table containing two numbers: the player ID and the item ID. Since this table would dynamically grow and shrink as needed, it would not add the bulk of extra fields on the main table that will likely mostly be empty for many players.
The indelible lord of tl;dr
jpoisson
Posts: 245
Joined: Sun Aug 02, 2009 5:12 pm

Re: Bank Tutorial

Post by jpoisson »

@Jackolantern - :cry: I couldn't put it better myself. Indeed it is much easier to maintain a one-to-many relationship compared to a many-to-many relationship.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Bank Tutorial

Post by hallsofvallhalla »

while it is a great idea to have a field that states whether it is in a bank or storage it may not be the best route for size reasons. Players often load up their storage and their banks. Imagine having 500 players. Each player has 10 items in their bank and 10 items in their storage. That's 10,000 items! Would you rather have 1 table holding all this or 2?
User avatar
Ravinos
Posts: 281
Joined: Tue Sep 15, 2009 4:14 pm

Re: Bank Tutorial

Post by Ravinos »

So Halls, we should move the equipped items to a separate table then too? :mrgreen: Each character can have up to 10 equipped items in my game.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Bank Tutorial

Post by hallsofvallhalla »

10 items is different than 10 bank and 10 storage.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Bank Tutorial

Post by Jackolantern »

Having them in separate tables is probably the best bet. MySQL honestly doesn't care how many tables you have. After about 10,000, your OS will begin to freak out regardless of it being Linux, Windows or OSX, but MySQL could care less. It is better to have more smaller, completely filled out tables than to have less tables that are longer with many empty fields. Longer tables with more fields will slow down queries whereas having many tables makes no difference to performance at all until the OS begins to choke (which again, is a huge number of tables that is likely too much for one or two developers to keep up with).
The indelible lord of tl;dr
User avatar
Ravinos
Posts: 281
Joined: Tue Sep 15, 2009 4:14 pm

Re: Bank Tutorial

Post by Ravinos »

I may have to start rethinking my tables then. The longest table I have is 20 fields and none are empty. Everything else is 15 or less. Before I went to work I went ahead and separated all of my toggles into new tables and It definitely seems to speed things up a bit. I still need to redo my auction house though.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Bank Tutorial

Post by Jackolantern »

20 fields isn't that bad, really. When people in the MySQL community talk about having too many fields, they are usually talking about business-oriented applications that may have upwards of 200 or 300 fields on one monolithic table.
The indelible lord of tl;dr
User avatar
Ravinos
Posts: 281
Joined: Tue Sep 15, 2009 4:14 pm

Re: Bank Tutorial

Post by Ravinos »

I've don't see the need in a game like this to have that many fields. Right now my users has 20 fields and some of them are placeholders for systems that I haven't put in yet lol
Last edited by Ravinos on Wed Mar 03, 2010 4:56 pm, edited 1 time in total.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Bank Tutorial

Post by hallsofvallhalla »

The hard coded limit is 4096 fields per table. This number though depends on the data size of each row. You cannot exceed 64k.
Post Reply

Return to “Tutorials”