logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Database vs In Mod Storage
Goto page 1, 2  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related
View previous topic :: View next topic  
Author Message
ArielT



Joined: 26 Jan 2010
Posts: 30

PostPosted: Mon May 03, 2010 0:39    Post subject: Database vs In Mod Storage Reply with quote

So, which would be more efficient for storing/accessing 2DA information if I wanted to preload 2DAs?

A) Store the 2da in a table in an SQL database
-or-
B) Store the 2da on a way point object in the module
Back to top
View user's profile Send private message MSN Messenger
Disco



Joined: 06 Dec 2006
Posts: 152

PostPosted: Mon May 03, 2010 13:21    Post subject: Reply with quote

Depends on what you exactly want to do, I'd say. I wouldn't store the whole spell.2da on a waypoint.

Since 1.6x 2da caching has become less of a bottleneck, as far as I know. We (Amia) just let the engine do the work. I do cache things like ban lists and who is a DM on waypoints, though. Those things are in the database but don't change often enough to warrant a full db query for every login, as far as I am concerned.
Back to top
View user's profile Send private message
Terra_777



Joined: 27 Jun 2008
Posts: 216
Location: Sweden

PostPosted: Mon May 03, 2010 13:57    Post subject: Reply with quote

Getting data from a 2da is much faster then getting the 500th+ local variable entry off an object.
_________________
I dun have any signature, I'm happy anyway.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Mon May 03, 2010 15:27    Post subject: Reply with quote

if your datas got more then one column, 2da or database is your friend, both for efficiency and scripting simplicity

then if you want search in those datas, database is your friend, if not 2da is enough
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Tenshar



Joined: 18 Apr 2010
Posts: 13

PostPosted: Sat Jul 03, 2010 22:27    Post subject: Reply with quote

This may sound noobish, but how do you store something on a waypoint? I don't have SQL and my host doesn't want me to use it so i have no experience with MySQL at all. can you only store 2das on waypoints or can you store other stuff like integers?
If you can store integers on them, do they stay on it after reset?
Thx

-Tenshar Wink
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sun Jul 04, 2010 0:35    Post subject: Reply with quote

Okay.

1) make new empty location and create waypoint with tag "2DA_spells" there
2) add this script into your OnModuleLoad event:
Code:

object oWP = GetWaypointByTag("2DA_spells");
int nLine;
int nLastLine = 839;//change this to reflect your 2da last line
string sData, sLine;
 while(nLine <= nLastLine)
 {
 sLine = IntToString(nLine);
 sData = Get2DAString("spells","Label",nLine);
 SetLocalString(oWP,"Label_"+sLine,sData);
 sData = Get2DAString("spells","Name",nLine);
 SetLocalString(oWP,"Name_"+sLine,sData);
 //etc.
 nLine++;
 }

You can also set some values as integer and I doubt if you really need all collumns.
3) Compile it and run test game via F9.
4) Save game.
5) Find the saved game (NWN/saves) rename "*.sav" to "_*.mod" and copy it into module folder
6) open new module and find that location and export it
7) open real module and import that location
8 ) copy waypoint inside anywhere else and delete that area

very nice trick

then to retrieve 2da value from waypoint you need new custom function like this
Code:
string GetCached2DAString(string s2da, string sColumn, int nRow);
string GetCached2DAString(string s2da, string sColumn, int nRow)
{
return GetLocalString(GetWaypointByTag("2DA_"+s2da,sColumn+"_"+IntToString(nRow));
}

_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Tenshar



Joined: 18 Apr 2010
Posts: 13

PostPosted: Sun Jul 04, 2010 15:05    Post subject: Reply with quote

Thx, I got another question though,
If an integer is stored on a placeable or waypoint or something by a player, will the integer still be there after a server reset?
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sun Jul 04, 2010 15:35    Post subject: not unless Reply with quote

Things on placeables, local vars etc, get wiped at a server reset, because the object is essentially destroyed.

If you were to store the placeable in a local campagin database, that would store all the vars on it, but that goes back to file reading and writing operations, which are slow.
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Sun Jul 04, 2010 15:38    Post subject: Reply with quote

SCO/RCO don't work on placeables.
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sun Jul 04, 2010 15:39    Post subject: Reply with quote

ah

K - Then no.... there is no way to save local vars without database storage.
Must be on a creature or item. Lol
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sun Jul 04, 2010 16:16    Post subject: Re: not unless Reply with quote

Baaleos wrote:
Things on placeables, local vars etc, get wiped at a server reset, because the object is essentially destroyed.

If you were to store the placeable in a local campagin database, that would store all the vars on it, but that goes back to file reading and writing operations, which are slow.
not by method I described
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sun Jul 04, 2010 16:19    Post subject: true and false Reply with quote

True, the 2da data is stored securely on your waypoint, but its not writeable/saveable, it will always be at the state it was in toolset..

Its a purely read only storage.

If however, the waypoint, was swapped out with a creature instead, then it could be read/writable, because you could have it set to store all of its 2da's in a database every 10 minutes or something - or just when it has its data changed.

Then on mod load, it restores the 'fresh' data.


But as you say... for what he needs, it would work perfectly.
Back to top
View user's profile Send private message
Tenshar



Joined: 18 Apr 2010
Posts: 13

PostPosted: Sun Jul 04, 2010 19:18    Post subject: Reply with quote

Baaleos wrote:
ah

K - Then no.... there is no way to save local vars without database storage.
Must be on a creature or item. Lol


So your saying If I stored the integers on an NPC it would stay there after a reset?
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sun Jul 04, 2010 19:45    Post subject: yes Reply with quote

Yes... but they will do that on a waypoint too anyway.


What im pointing out is 2 things.


1. Waypoints cannot be stored into databases, which means that you wont be able to update the data that is stored on them, and save it, so that the new data is there when you reset the module.

2. Creatures however, can be stored into databases, meaning that the data stored on them, can be updated, and then saved between resets.


But in the case of your waypoint system, it is storing 2da strings, which are not likely to change, which therefore would not require you to make it possible to update and save the data beyond a reset.


If you open the module in toolset, you will see that the waypoint will have the 2da strings on it as variables, these are stored permanently to that placeable, unless removed.

Everytime you restart the module, that waypoint will be restored to this 'state'.


My suggestion about using creatures, was just in the event that you wanted to update the data.
eg - Add some additional 2da string values, without having to go through the process of saving a game, move the sav file to module folder, rename, toolset, export etc....


But for what you want this to do, storing 2da data statically on a waypoint, the method posted above, will work perfectly for what you require, no need to use creatures, although creatures would work just as well.
Back to top
View user's profile Send private message
Tenshar



Joined: 18 Apr 2010
Posts: 13

PostPosted: Sun Jul 04, 2010 23:34    Post subject: Reply with quote

Actually, I do want the data to be updated because, when players use a specific tool it saves their public CD-Key on a placeable, and when the rest, die or log on it checks if theyre public cd key is on that npc and if it is it applies certain effects to then, this stays after relogging but not after a reset, so If I use an NPC instead of a placeable it should save the data and stay there after a reset right?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group