Datafile
Include for handing data files.
Including Code
include ":datafile:datafile";
DFOpenDataFile()
Creates a datafile handler.
DFOpenDataFile(file_name, create:=DF_NO_CREATE, flags:=DF_KEYTYPE_STRING)
Parameters
Description
filename
Path and name of the data file. (Example ":pkg-name:file-name"
)
create
Creation flags:
DF_NO_CREATE
- Will return an error if the datafile does not exist. *DefaultDF_CREATE
- Will create the datafile if it does not exist.
flags
Datafile.em flags:
DF_KEYTYPE_STRING
- Elem names will be handled as strings.DF_KEYTYPE_INTEGER
- Elem names will be handled as integers.
DFFindElement()
Creates a datafile elem handler.
DFFindElement(byref file_ref, elem_name, create:=DF_NO_CREATE)
Parameters
Description
file_ref
Data file to retrieve/create the element in.
elem_name
Name of the element to retrieve.
create
Creation flags:
DF_NO_CREATE
- Will return an error if the data elem does not exist. *DefaultDF_CREATE
- Will create the data elem if it does not exist.
DFGetElemNames()
Retrieves a list of all elem names that are in a data file.
DFGetElemNames(byref file_ref);
Parameters
Description
file_ref
The datafile to retrieve the elem names in.
DFGetElemProps()
Retrieves a list of all prop names that are in a data elem.
DFGetElemProps(elem_ref);
Parameters
Description
elem_ref
The data elem to retrieve the property names in.
DFGetProp()
Retrieves the information in a cprop, or assigns it a value if told to do-so.
DFGetProp(byref elem_ref, prop_name, create:=DF_NO_CREATE, assign_val:=0)
Parameters
Description
elem_ref
The data elem to retrieve the property from.
prop_name
The name of the property to retrieve.
create
Creation flags:
DF_NO_CREATE
- Will return an error if the property does not exist. *DefaultDF_CREATE
- Will create the property if it does not exist and an assign value is set.
assign_val
Value to set the property to if it is created.
DFPurgeFile()
Erases all elems in a datafile. (WIPES IT CLEAN)
DFPurgeFile(byref file_ref);
Parameters
Description
file_ref
The datafile to wipe.
Including Code
Это расширенный инклюд для работы с файлами, в нём уже встроен верхний инклюд.
include ":datafile:datafile_ex";
ConfigToDataFile()
Converts a config file to a data file.
This will purge the data file you are writing to!!
ConfigToDataFile(cfg_file, data_file);
Parameters
Description
cfg_file
Can be a reference to a config file or a path to one.
data_file
Can be a reference to a data file or a path to one.
DataFileToConfig()
Converts a data file to a config file.
DataFileToConfig(data_file, cfg_path);
Parameters
Description
data_file
Can be a reference to a data file or a path to one.
cfg_file
Must be a path to a config file (not a reference).
Code Examples
Пример на основе: pkg\utils\statistics\account.inc
use uo;
use os;
include ":datafile:datafile";
var stat_datafile := DFOpenDataFile( ":statistics:statistics", DF_CREATE );
function GetAccountProperty( acct_name, property )
var data_elem := DFFindElement( stat_datafile, acct_name );
return data_elem.GetProp( property );
endfunction
function SetAccountProperty( acct_name, property, value )
var data_elem := DFFindElement( stat_datafile, acct_name, DF_CREATE );
return data_elem.SetProp( property, value );
endfunction
function EraseAccountProperty( acct_name, property )
var data_elem := DFFindElement( stat_datafile, acct_name );
return data_elem.EraseProp( property );
endfunction
Last updated
Was this helpful?