Page 1 of 1

ReadConfigFile can't find cfg file

Posted: Sat Jul 11, 2009 2:54 am
by Gnafu
Hi everyone!

I have a problem with the ReadConfigFile function:

pol/scripts/include/setup.inc: // <- NOT a package

Code: Select all

use cfgfile;
var npccfg := readconfigfile("npcdesc");
pol/pkg/mypackage/my_ai.src: // <- IS a package

Code: Select all

include "setup.inc";

program blabla(){ 
// this code uses the npccfg variable
}
I get a "Config file not found" error.
The package does not have a npcdesc.cfg but the main npcdesc.cfg exists!
This script works if I write "::npcdesc" instead of "npcdesc"

As the docs says:

Code: Select all

If only 'cfgfile' is passed, POL looks for it first in /pol/config and then in each package sequentially.
If I change my include adding the "::" I won't be able to use npcdescs in the packages..
Am I doing something wrong?

Re: ReadConfigFile can't find cfg file

Posted: Sat Jul 11, 2009 2:58 am
by CWO
It doesn't matter where the inc is, it only matters where the src is. I believe you can use ":*:npcdesc" for all of them.

Re: ReadConfigFile can't find cfg file

Posted: Sun Jul 12, 2009 10:42 pm
by Gnafu
CWO wrote:I believe you can use ":*:npcdesc" for all of them.
Do you mean that using :*: the function will load all npcdescs as one file? Because it doesn't. :D
I'll do some testing soon.

Re: ReadConfigFile can't find cfg file

Posted: Mon Jul 13, 2009 1:45 am
by Targun
Check distro npcdesc handling it's the only reasonable way to do it.
includefile: :brainAI:npcUtil

Code: Select all

function NPC_GetNPCConfig(template)
	if ( !template.package )
		template := NPC_ParseTemplateName(template);
	endif

	var npc_cfg := ReadConfigFile(":"+template.package+":npcdesc");
	if ( npc_cfg.errortext )
		return error{"errortext":="Error::NPC_GetNPCConfig() - Could not open :"+template.package+":npcdesc ->"+npc_cfg.errortext};
	endif

	var cfg_elem := npc_cfg[template.template];
	if ( cfg_elem.errortext )
		return error{"errortext":="Error::NPC_GetNPCConfig() - Could not find elem ["+template.template+"] ->"+cfg_elem.errortext};
	endif

	return cfg_elem;
endfunction

function NPC_ParseTemplateName(template_name)
	if ( template_name.IsA(POLCLASS_NPC) )
		template_name := template_name.npctemplate;
	endif

	//Find positions of ":" characters
	var colon_a := Find(template_name, ":", 1);
	var colon_b := Find(template_name, ":", 2);

	var parsed := struct{"package", "template"};

	if ( !colon_a || !colon_b )
		//Not a complete package name - use default npcdesc.cfg
		parsed.package := "";
		parsed.template := template_name;
	else
		parsed.package := template_name[colon_a+1, colon_b-2];
		parsed.template := template_name[colon_b+1, Len(template_name)];
	endif

	return parsed;
endfunction

Re: ReadConfigFile can't find cfg file

Posted: Mon Jul 13, 2009 3:52 am
by Gnafu
Damn, I always forget that DISTRO IS THE WAY !!

Targun, your post improved my shard's flexibility by 20%, it is now 120% SKILL CAP!! :cheers: