Datafile.em and functions

Bug reports and feature requests. New features can only be added to the current development version. Bug-fixes may be back-ported.

Current release: 099 / Current development: 100
Post Reply
Harley
Forum Regular
Posts: 344
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

Datafile.em and functions

Post by Harley » Sun Mar 31, 2019 2:42 pm

Code: Select all

print( "Hello world!;-)" ); // GREETINGS
I don't know if someone has encountered this problem at POL100, but I had!

When I want to create new data file at data store, I can't do it and have an error, instead of if I have data file exists.

I use distro functions from datafile.inc
DFOpenDataFile()

Code: Select all

/*
 * DFOpenDataFile(filename, create, flags)
 *
 * Purpose
 * Creates a datafile handler.
 *
 * Parameters
 * 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. *Default
 *		DF_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.
 *
 * Return value
 * A datafile reference.
 *
 */
function DFOpenDataFile(file_name, create:=DF_NO_CREATE, flags:=DF_KEYTYPE_STRING)
	var data_file := OpenDataFile( file_name );
	if ( (!data_file) && (create) )
		DF_OutPut("Debug::DFOpenDataFile() - Creating data file: "+file_name);
		CreateDataFile( file_name, flags);
		data_file := OpenDataFile(file_name);
	endif

	if ( data_file )
		return data_file;
	elseif ( create )
		var errmsg := error{"errortext":="Error::DFOpenDataFile() - Could not open "+file_name+" : "+data_file.errortext};
		DF_OutPut(errmsg.errortext);
		return errmsg;
	endif
endfunction
And DFFindElement()

Code: Select all

/*
 * DFFindElement(byref file_ref, elem_name, create)
 *
 * Purpose
 * Creates a datafile elem handler.
 *
 * Parameters
 * 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. *Default
 *		DF_CREATE	Will create the data elem if it does not exist.
 *
 * Return value
 * A data file element reference.
 *
 */
function DFFindElement(byref file_ref, elem_name, create:=DF_NO_CREATE)
	var temp := file_ref.FindElement(CStr(elem_name));
	if ( !temp && create )
		DF_OutPut("Debug::DFFindElement() - Creating elem: "+CStr(elem_name));
		file_ref.CreateElement(CStr(elem_name));
		temp := file_ref.FindElement(CStr(elem_name));
	endif

	if ( temp )
		return temp;
	elseif (create)
		var errmsg := error{"errortext":="Error::DFFindElement() - Could not open data elem ["+elem_name+"] - "+temp.errortext};
		DF_OutPut(errmsg.errortext);
		return errmsg;
	endif
endfunction
I called them when created new datastore at POL099 and all works best!
When I migrate to POL100, I have a lot of errors in my scripts with use npc; but this is not in that time.

So, I call DISTRO functions and send parameters to them:

Code: Select all

	var file_name := ":staff:" + who.acctname + "_" + who.name;
	var data_file := DFOpenDataFile( file_name, DF_CREATE );
	if( data_file.errortext )
		SendSysMessage( who, "Something wrong with [DataFile] 'Open'!", 3, 37 );
		SysLog( "\n	Error starting function DFOpenDataFile() at include <:datafile:inc_public/datafile> -->\n	"+ data_file.errortext );
		return 0;
	endif
	
	var elem_name := who.serial;
        var data_elem := DFFindElement( data_file, elem_name, DF_CREATE );
	if( data_elem.errortext )
		SendSysMessage( who, "Something wrong with [DataFile] element 'Find'!", 3, 37 );
		SysLog( "\n	Error starting function DFFindElement() at include <:datafile:inc_public/datafile> -->\n	"+ data_elem.errortext );
		return 0;
	endif
And there is an error:
Error starting function DFOpenDataFile() at include <:datafile:inc_public/datafile> -->
Error::DFOpenDataFile() - Could not open :staff:admin_Admin : Error in descriptor
So, what is the problem - I don't know! I thought about some settings in pol.cfg, but these are just some guesses and what exactly can influence it there, I don't know.


p.s.
If someone know how to resolve it - please, let me know as soon as possible, because in the other side, I have to migrate back to POL099.

UPDATE after 5 minutes:
I decided to check my previous package that I've made at POL099, which create datastore package at data/ds location and do you know what? Nothing!) If there isn't specific package, it won't create it! :deadhorse:

With best regards!

DevGIB
Grandmaster Poster
Posts: 220
Joined: Mon Feb 06, 2006 6:12 am

Re: Datafile.em and functions

Post by DevGIB » Sun Mar 31, 2019 4:11 pm

As far as i'm aware the datastore has to be related to a specific package and you can't have for example a datastore named StaffDS if the package name is Staff and a StaffDS package does not exist.

I wanted to have a package name where the function of the package was 1 thing, but the data that got stored was better named something else more relative to the data that was actually being stored, and it didn't work i ended up having to store it under the package name. With that said obviously the individual data files can be named what you like.

guialtran
Grandmaster Poster
Posts: 119
Joined: Wed Jul 30, 2008 12:42 pm

Re: Datafile.em and functions

Post by guialtran » Sun Mar 31, 2019 8:01 pm

the datafile can be created without a reference to a package.
What he does not allow is you refer to a package that does not exist.

:test:namefile

if you want to create the file without package, this is not a problem, when referencing the name do not use ":pkg:

when the server saves, the datafile file will be created in the root of the "data/ds folder" :deadhorse:
Image Zulu Hotel Forgotten Realms
Imagewww.zuluhotel.com.br
Image Discord Cronos#8404

Harley
Forum Regular
Posts: 344
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

Re: Datafile.em and functions

Post by Harley » Mon Apr 01, 2019 2:19 am

guialtran wrote:
Sun Mar 31, 2019 8:01 pm
the datafile can be created without a reference to a package.
What he does not allow is you refer to a package that does not exist.

:test:namefile

if you want to create the file without package, this is not a problem, when referencing the name do not use ":pkg:

when the server saves, the datafile file will be created in the root of the "data/ds folder" :deadhorse:
Hm.. in other words, if some folder with the same name in pkg.cfg doesn't exists, datafile will not create it.
Right?

guialtran
Grandmaster Poster
Posts: 119
Joined: Wed Jul 30, 2008 12:42 pm

Re: Datafile.em and functions

Post by guialtran » Mon Apr 01, 2019 8:27 pm

if you have it created using this signature: "pkgname: filename" will not be created.
but if you put "filename" it can create.


this signature "pkgname: filename" makes it create the file inside a folder with the package name.

with this signature "filename" it creates in the root of the ds folder
Image Zulu Hotel Forgotten Realms
Imagewww.zuluhotel.com.br
Image Discord Cronos#8404

Post Reply