Config File

From Bohemia Interactive Community
Jump to navigation Jump to search

Description: A handle that is used in VBS1 to communicate with config files. The handle can represent either the whole config file (which can be saved or loaded into a disc file), or one class within it.


Saving to a file

; get handle to new file
_file = newconfig

; write a value to the file
_file addvalue ["MyValue",2]

; write a class to the file
_class = _file addclass "MyClass"

; write a value to the class
_class addvalue ["AnotherValue",4]

; save the file
_file saveconfig "MyFile.txt"

The above code would create [vbs user directory]\users\[username]\config\MyFile.txt, and MyFile.txt would contain:

MyValue=2.000000;
class MyClass
{
   AnotherValue=4.000000;
};

Reading a file

; get handle to existing file
_file = loadconfig "MyFile.txt"

; read a value
_myvalue = _file getvalue "MyValue" 

; open a class
_class = _file openclass "MyClass"

; read a value in the class
_anothervalue = _class getvalue "AnotherValue"