Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-12-2009, 08:09 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
SQL Item System

So, I've designed an SQL item system, the only problem that I don't like is the loading of the data and the time it's taking to request things from it. Is there any possible way to speed this up? Or am I doing something wrong... thanks
Reply With Quote
  #2  
Old 05-12-2009, 08:45 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
How -are- you doing it?
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #3  
Old 05-13-2009, 05:41 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Quote:
Originally Posted by xXziroXx View Post
How -are- you doing it?
Stored items in an SQL database, getting the item data from the database by an ID of the item. On login/item adding it's copying the values from the ID and storing them as ''player.item_id.var''.
I was going to create a table to contain players accounts and such...

thanks
Reply With Quote
  #4  
Old 05-13-2009, 07:06 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by [email protected] View Post
Stored items in an SQL database, getting the item data from the database by an ID of the item. On login/item adding it's copying the values from the ID and storing them as ''player.item_id.var''.
I was going to create a table to contain players accounts and such...

thanks
still not a very thorough explanation.

How do you determine what items to look up for an individual player?
Reply With Quote
  #5  
Old 05-13-2009, 07:46 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Oh- just as a flag
flag = {id, amount}
Reply With Quote
  #6  
Old 05-13-2009, 07:50 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by Mark Sir Link View Post
still not a very thorough explanation.

How do you determine what items to look up for an individual player?
The SQL database contains all the data for the items, while the player simply holds the ID's for the items they own. He looks up the ID for the item in the database and loads them onto the player.
Reply With Quote
  #7  
Old 05-13-2009, 09:17 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Are you using transactions (instead of just using single commands)?
Inverness mentioned this to me yesterday; I don't know for sure that Graal even supports transactions, so let me know if I'm wrong.
__________________
Reply With Quote
  #8  
Old 05-13-2009, 09:23 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Do you have the id set as the primary key?
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #9  
Old 05-13-2009, 09:38 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by napo_p2p View Post
Do you have the id set as the primary key?
He's actually using alphanumeric ID's for actual reference(easier to add "swordtest1" rather than "231" or whatever numeric ID is assigned).
Reply With Quote
  #10  
Old 05-13-2009, 09:56 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
If you're doing like

NPC Code:
SELECT * FROM items WHERE itemid=swordtest1



Have you set that 'itemid' is UNIQUE when creating the table?

NPC Code:
CREATE TABLE items(itemid TEXT UNIQUE DEFAULT '')



That would make it easier to index and faster to recall.
__________________
Reply With Quote
  #11  
Old 05-13-2009, 10:11 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Here's how I'm doing it on Maloria.


Table creation...
NPC Code:
CREATE TABLE items (entry_index INTEGER PRIMARY KEY AUTOINCREMENT, account VARCHAR NOT NULL DEFAULT 'ACCOUNT_ERROR', item_id VARCHAR NOT NULL DEFAULT 'ID_ERROR', item_data VARCHAR NOT NULL DEFAULT 'DATA_ERROR')



Loading of items...
NPC Code:
SELECT * FROM items WHERE account = '" @ player.account @ "'"



Then I just loop through the query and add each item to player.items which is a TStaticVar that gets cleared everytime the player logs out.

I also automatically save all the players current items to the SQLite database upon onPlayerLogout().
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #12  
Old 05-14-2009, 02:47 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Player should not have ids of items he owns, rather the items should have the account name of the player they belong to. The items should also be indexed by their account name.
Quote:
Originally Posted by xXziroXx View Post
<snip>
#1. Why are you using AUTOINCREMENT?
#2. Do you know that the INTEGER PRIMARY KEY column is an alias for the built-in rowid column?
#3. VARCHAR is not a type in SQLite, it is just changed to TEXT, I suggest using that.
#4. If you only update the SQL when the player logs out then you're not using SQL correctly.
__________________

Last edited by Inverness; 05-14-2009 at 03:13 AM..
Reply With Quote
  #13  
Old 05-14-2009, 05:39 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Aha- I see! So only on login/logout, I see the benefits to that actually! Thank you

Just wondering, I see you're replicating data in your database (each item having it's own item data- I don't plan on using this) so I think I'll stick with storing the items in the strings, thanks again
Reply With Quote
  #14  
Old 05-14-2009, 05:57 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
For speeding things up you can create an index (create index) on certain columns, that can make queries 100-1000 times faster.
Reply With Quote
  #15  
Old 05-14-2009, 05:59 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
Yeah- they're indexed. Thanks

Where would you recommend to save items @ Stefan. (the flags)
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:09 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.