Author Topic: Data management? [Solved]  (Read 1621 times)

Alright, I plan on working on a mod that is going to require a forget ton of client variables, and it needs to save and load them when the client leaves/joins.

I'm used to writing text files and reading them, but this is a very inefficient way of doing it, I've head something about script objects and what not.

Can someone go in depth with a good database system?
« Last Edit: July 04, 2013, 11:21:48 AM by Yenola »

Script objects are objects that are useless unless you're going to take full advantage of them. They work in a similar way than to other objects; you can do absolutely anything with script objects, and even put them into script groups which'll create organisation within a database.

Here's some tutorials I've looked up on the internet which'll benefit you more than my attempt at any explanation.

Iban Explains it All

(Could only find one, I'll update the post if I find more useful tutorials.)

Also I should consider you check out some database orientated add-ons and investigate and edit around with them.

A good database system only writes what it needs to when it needs to do it.

Minus periodic backups of course.

And what exactly do you need to store? How much is a 'forgetton?' 50? 100? 1000? More?

I'm used to writing text files and reading them, but this is a very inefficient way of doing it

It's only inefficient if the programmer doesn't know how write an efficient system to handle the file objects.

A good database system only writes what it needs to when it needs to do it.

A good database system only writes what it needs to when it needs to do it.

Minus periodic backups of course.

And what exactly do you need to store? How much is a 'forgetton?' 50? 100? 1000? More?
Somewhere between 50-100 variables on each client.



It's only inefficient if the programmer doesn't know how write an efficient system to handle the file objects.


I have no idea how to edit each line of a file, so I'd be creating a folder for each client and having 50 - 100 different .txt files with a variable stored in each, aka inefficient



Script objects are objects that are useless unless you're going to take full advantage of them. They work in a similar way than to other objects; you can do absolutely anything with script objects, and even put them into script groups which'll create organisation within a database.

Here's some tutorials I've looked up on the internet which'll benefit you more than my attempt at any explanation.

Iban Explains it All

(Could only find one, I'll update the post if I find more useful tutorials.)

Also I should consider you check out some database orientated add-ons and investigate and edit around with them.


Will look into it, thank you

Somewhere between 50-100 variables on each client.



I have no idea how to edit each line of a file, so I'd be creating a folder for each client and having 50 - 100 different .txt files with a variable stored in each, aka inefficient
100 variables isn't a lot. Believe me I've had more.

And for how to go about writing these variables, making 100 different files is NOT an option. No.

All you have to do is use .openForWrite (which will clear the file) and write all the variables into it at the same time. Just make sure that it only writes when it absolutely has to, like when the client leaves the game.

100 variables isn't a lot. Believe me I've had more.

And for how to go about writing these variables, making 100 different files is NOT an option. No.

All you have to do is use .openForWrite (which will clear the file) and write all the variables into it at the same time. Just make sure that it only writes when it absolutely has to, like when the client leaves the game.
The only problem I have with that is how to retrieve the variables correctly

Store variables in the client as .var_varname
Save each variable in format varname TAB value
for loading use .var_[varname] = value

y'all are batstuff crazy

Ok so here's what you do in torquestuff, do it right in other languages though

Assign all the values to bl_id tied global variable arrays: $ImportantData[%bl_id,%thing] = "stuff";

Then do export("$ImportantData*", "path/to/database.cs");

To import do exec("path/to/database.cs");

This stuff is hyperfast, run some benchmarks and be amazed

One tiny flaw: needs data sanitization. You don't want to find out some noob named himself ;eval(quit();) orsomething worse.
>>> $ImportantData16807_firstName = ;eval(quit);

Just ban semicolons and parenthesies and you're probably fine tho
« Last Edit: July 03, 2013, 07:42:08 PM by Lugnut »

Store variables in the client as .var_varname
Save each variable in format varname TAB value
for loading use .var_[varname] = value
But how do I retrieve them from the file correctly?

Okay let me explain this further.

our two vars for BL_ID 19002:
.var_money
.var_corn

Save them into the text file labeled "19002.txt" the file looks like this when opened:
money 1 corn 1

Now how do I get these values back into Torque, I have very little experience with reading files in Torque

y'all are batstuff crazy

Ok so here's what you do in torquestuff, do it right in other languages though

Assign all the values to bl_id tied global variable arrays: $ImportantData[%bl_id,%thing] = "stuff";

Then do export("$ImportantData*", "path/to/database.cs");

To import do exec("path/to/database.cs");

This stuff is hyperfast, run some benchmarks and be amazed
This is what I wanted to do, but it when a player connects I have to execute the entire file again, if I get a lot of players that's going to get intensive

This is what I wanted to do, but it when a player connects I have to execute the entire file again, if I get a lot of players that's going to get intensive
Why would you have to execute it again?

Why would you have to execute it again?
The idea escaped my mind for the second, I've decided to got that route, thanks guys

One tiny flaw: needs data sanitization. You don't want to find out some noob named himself ;eval(quit();) orsomething worse.
>>> $ImportantData16807_firstName = ;eval(quit);

Just ban semicolons and parenthesies and you're probably fine tho
I'm pretty sure the values get put into "" when using export, right?
So if you prefix all " with a \ it should be fine.

I'm pretty sure the values get put into "" when using export, right?
So if you prefix all " with a \ it should be fine.
things like $butts["poop gee willikrs"] will be exported as $buttspoop gee willikrs i'm at least 98% certain because i had a problem with this just several days ago
oops i'm dumb that's not what you ment!