variables in other file

Discussions about Coding and Scripting
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

variables in other file

Post by Rakiayn »

I would like to make some variables which write to a file in the system folder
and later in the script call to variables from the file in the system folder
but im not sure how it works. how are these vars called and written to the file.
automaticly?
if so, is there a way to update from and to the file in the system folder only when you want to?
User avatar
Feralidragon
Godlike
Posts: 5502
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: variables in other file

Post by Feralidragon »

Basically, you want to write to your own ini, right?

1 - First off, the name of the file is defined in the class definition itself, also several different classes may refer to the same file, no problem there:

Code: Select all

class A extends B config(myIniFileName);
2 - Only variables with the modifier "globalconfig" and "config" are allowed to be defined and written in the ini file:

Code: Select all

var() config bool foo;
var() globalconfig float k;
var config name somedata;
I don't know the exact difference between globalconfig and config, but afaik (not sure, someone correct me if I am wrong): globalconfig will force the value of that variable from the parent class down to the subclasses, no matter what you configure in the subclasses regarding that variable in specific, while config from the parent class will only be used by the subclasses if you don't configure them as well in the ini.

3 - To load the variable value, that's simple, if you have:

Code: Select all

var() config float SomeValue;
You load the value as:

Code: Select all

Something = default.SomeValue;
When there's an ini, the default value will be the value in the ini, if no ini is found, the default value you defined on compile will be used instead.

4 - To save, using the example variable above, it's done this way:

Code: Select all

SaveConfig();
or

Code: Select all

StaticSaveConfig();
Personally, I don't know the difference between the 2 of them, but from the function definitions and nomenclatures I think they work this way (again, someone correct me if this stands to not be accurate):
- SaveConfig() exists to be called from instances only, and the CURRENTvariable values will be saved as they are in that instance;
- StaticSaveConfig() can be called anywhere, including static functions in reference to the respective class. Consequently it only considers changes on the current DEFAULT values to be saved into the ini.

5 - Keep in mind that the ini will be auto-generated ONLY when you actually save something there (or make a ResetConfig()), but you can create manually your own ini file up and it will always be read, in case the variable names and package definitions are correct to be recognized.
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

Re: variables in other file

Post by Rakiayn »

great explanation :D
User avatar
Rakiayn
Masterful
Posts: 550
Joined: Fri Aug 28, 2009 3:33 pm

Re: variables in other file

Post by Rakiayn »

and in online play, does the client have acces to his own file ? or the file of the host?
User avatar
Feralidragon
Godlike
Posts: 5502
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: variables in other file

Post by Feralidragon »

Rakiayn wrote:and in online play, does the client have acces to his own file ? or the file of the host?
The client will only have access to his own file, never the host one. Each machine read their own file: server -> server side file, client -> client side file.
What generally happens, is that the server-side file is read by the server itself, and upon processing and function calls the "final results" of the server are replicated to the client.