Raised This Month: $32 Target: $400
 8% 

How To: Save Data


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 04-19-2005 , 10:26   How To: Save Data
Reply With Quote #1

I've been seeing a lot of confusion over how to save data cross mapchange/server disconnect, so I wanted to write a tutorial on how to correctly pick and save data.

There are four basic ways to save data cross mapchange, and three cross server disconnect:

1. Files <direct>
2. Vault Systems <files indirect>
3. MYSQL
4. ArrayX

ArrayX is a dynamic array module that is not quite done yet, so I will not go into detail about it quite yet. It will, however, support cross map change dynamic storage.

Step 1: Choosing your saving method.

Choosing a saving method can be a little confusing to some, so follow these simple rules:

FILE:
For very small settings, you might want to use a direct file.

For example, if you need to save five variables cross server connect, you might wanna just use a file system.

In addition, if you want to save things that cannot easily be saved into the vault, your not going to want to use vault or mysql.

For a quick and simple file system, I rescripted and tested CVault, which is stocks for making a simple file vault systems, no module.

VAULT:
If a file solution is not for you, then perhaps a Vault solution is best.

If you need to save a few entries, you can probably use Vault.
Vault (default) lags like hell, but if your not using it too much, its very simple to use.

If you need to save and recover hundreds of entries, with lightning fast speed, and the capability for various vault files, and you don't feel like compiling NVault or waiting, VaultX might be best for you.

If you don't care about the amount of RAM you might use, and want faster Has Table saving, you might wanna pick NVault over VaultX.

MYSQL:
If you don't care about the end user, or need to save thousands upon millions of entries, all in one database, MYSQL might be for you.

Also, if you want info from one server to go to another and do not feel like working with SOCKET module, MYSQL is for you.

However, the speed of MYSQL (even on local DB's), can actually be slower then NVAULT and VAULTX, thus negating some of its usefulness.

Step 2: Saving
Now you've decided which method to save using, you'll have to learn how to save to it right?

Files:
You can direct write and read to a file using the write_file, read_file commands.

However, I like to do it with a simply custom vault system:

Code:
// CVAULT // Superior storing mechanism // Allows for a vault-like system with more options, ease of use, and speed. // All the real work is done through cvault_exists // Sets a particular key/value pair into the vault file (file[]) public set_cvaultdata(file[],key[],data[]){     // use exists to get the line     new currline[192], blank[128]     new line = cvaultdata_exists(file,key,blank)     // Format the key/value pair     format(currline,191,"%s %s",key,data)     // Write them     write_file(file,currline,line)     // return the line for future use     return line; } // Gets a particular key/value pair. Take all of exists credit, is really just a public. public get_cvaultdata(file[],key[],data[]){     // Find the value     new line = cvaultdata_exists(file,key,data)     // Return where it is.     return line; } // Removes a key/value from the vault. public remove_cvaultdata(file[],key[]){         // Find the key/value pair     new data[128]     new line = cvaultdata_exists(file,key,data)     // Over write them     write_file(file,"",line)     // Return the now free line     return line; } // The meat and gravy of CVAULT. Finds out where the key/value is, what it contains, and any free lines along the way. public cvaultdata_exists(file[],key[],data[]){     // Variables for line, key, and value data.     new currline[192]     new currvalue[128];     new currkey[64];     // What line are we on, how many letters are on it, and whats the last free line     new line = 0;     new txt;     new free_line = -1;     // File has to exist     if( file_exists(file) ) {         // Run through the entire file         while( ( line = read_file(file,line,currline,192,txt ) ) ){             // If its not commented out, continue             if( !equal( currline,"//", strlen("//") ) && !equal( currline,";",strlen(";") ) ) {                 // Break it into a key and a value                 strtok(currline, currkey, sizeof(currkey), currvalue, sizeof(currvalue),'   ',1);                                 // If its the key we are looking for, copy the data and return where itis                 if(equal(currkey,key)){                     copy(data,128,currvalue);                     return line-1;                 }                 // If its a free line, store that too                 else if( equal(currkey,"") ) free_line = line-1;             }         }     }         // If there isnt a file, there are no values either. So make the file.     else write_file(file, "// **** Cvault V1.117 Storage Method ****", 0);     // And return the last free line, just in case.     return free_line; }

However, you could just use write_ and read_ to read direct lines, if you know exactly what line it is on.

I recommend using the CVault I just provided if you want to save maybe like, some default values, that have nothing to do with players.

Otherwise, use a VAULT system thats a module:

VAULT:
Vault have a few simple commands:

Code:
get_vaultdata(key[],value[],len) remove_vaultdata(key[]) set_vaultdata(key[],value[]) vaultdata_exists(key[])

The default vault saves to ONE file, and allows you to get a key/value pair. It allows you to store data easily.

For example:
set_vaultdata("Default_Time","1.00")

Then you can get it back, no matter what map it is in.

However, default Vault is very laggy, and does not allow custom files.

VaultX and NVault (which I am not versed in, so will not mention ever again)

VaultX simply makes you set the path to the file you want, then use commands as normal.

Example:
set_vaultxpath();
set_vaultxdata("key","value")

VaultX allows for much better vaulting then default vault, and much faster.

MYSQL

Mysql module is fairly complex, and so will take some time to discuss.
When I get home, I will describe how to effectively use it.

This Tutorial is incomplete, due to the fact I am writing it away from my home computer, so I will finish it later tonight.

- Mel
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
XunTric
BANNED
Join Date: Jan 2005
Location: Norway/Norge
Old 04-19-2005 , 10:51  
Reply With Quote #2

Nice... Ill maybe add this to my XP Tutorial later...
(If its ok for you...?)

Btw is it there you got the idea?
XunTric is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 04-19-2005 , 12:46  
Reply With Quote #3

No, actually its not. I am just sick of people asking me how to use VaultX, why their crappy MYSQL coding doesnt work, etc.

And you can link to it, but this tutorial is entirely seperate.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
BioHazardousWaste
Senior Member
Join Date: Apr 2005
Location: Ontario, Canada =)
Old 04-19-2005 , 15:50  
Reply With Quote #4

Whoa, sounds like Twilight is a bit hot under the collar. Relax dude It's the down side of being famous, everybody wants you! lol Seriously though, you released vaultx without an example file; of course people are going to ask for your help.
__________________
"What then is truth? Truths are illusions which we have forgotten are illusions - they are metaphors that have become worn out... this (truth) is the duty to lie according to a fixed convention.

-Friedrich Nietzsche
BioHazardousWaste is offline
Send a message via MSN to BioHazardousWaste
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 04-19-2005 , 22:46  
Reply With Quote #5

If you read the thread, you can use VaultX. Also, why ask me about MYSQL?

I'm not famous at all tbh.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
Reply


Thread Tools
Display Modes

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 -4. The time now is 20:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode