ReadConfigFile can't find cfg file

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
Gnafu
Grandmaster Poster
Posts: 136
Joined: Thu Feb 02, 2006 7:29 am

ReadConfigFile can't find cfg file

Post 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?
User avatar
CWO
POL Expert
Posts: 1160
Joined: Sat Feb 04, 2006 5:49 pm

Re: ReadConfigFile can't find cfg file

Post 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.
Gnafu
Grandmaster Poster
Posts: 136
Joined: Thu Feb 02, 2006 7:29 am

Re: ReadConfigFile can't find cfg file

Post 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.
Targun
Neophyte Poster
Posts: 30
Joined: Wed Jul 23, 2008 8:03 am

Re: ReadConfigFile can't find cfg file

Post 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
Gnafu
Grandmaster Poster
Posts: 136
Joined: Thu Feb 02, 2006 7:29 am

Re: ReadConfigFile can't find cfg file

Post 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:
Post Reply