Page 1 of 1

GetConfigStringKeys() on elements with no key names

Posted: Fri May 05, 2006 2:59 pm
by tekproxy
Here's my armrzone.cfg (it's unmodified):

Code: Select all

ArmorZone
{
	Name	Body
	Chance	44
	Layer	13
	Layer	20
	Layer	22
	Layer	5
	Layer	17
}

ArmorZone
{
	Name	Arms
	Chance	14
	Layer	19
}

ArmorZone
{
	Name	Head
	Chance	14
	Layer	6
}

ArmorZone
{
	Name	Legs/feet
	Chance	14
	Layer	4
	Layer	3
	Layer	24
}

ArmorZone
{
	Name	Neck
	Chance	7
	Layer	10
}

ArmorZone
{
	Name	Hands
	Chance	7
	Layer	7
}
Here's a test text command that should print out the number of armor zones and a list of all of the zone names:

Code: Select all

use uo;
use os;
use cfgfile;

program TestRead(character, textcmd)
	var cfg_file := ReadConfigFile("::armrzone");
	var cfg_keys := GetConfigStringKeys(cfg_file);

	// Only prints out 1!
	SendSysMessage(character, "Armor zones: " + cfg_keys.size());
	
	var zones := "";
	
	foreach zone in cfg_keys
		zones := zones + " " + cfg_file[zone].Name;
	endforeach

	// Only prints out "Body"!	
	SendSysMessage(character, "Zones:" + zones);
endprogram

Only the first zone is loaded, and the rest are ignored. However, it works fine if I give the elements names. Why not simply load all of the elements with "" for their name instead of only loading the first one?

By the way, this took me a LONG time to figure out. :( I almost died.

Solution

Posted: Fri May 05, 2006 3:05 pm
by Austin

Code: Select all

ArmorZone Body
{
   Name   Body
   Chance   44
   Layer   13
   Layer   20
   Layer   22
   Layer   5
   Layer   17
}

ArmorZone Arms
{
   Name   Arms
   Chance   14
   Layer   19
}

ArmorZone Head
{
   Name   Head
   Chance   14
   Layer   6
}

ArmorZone Legs/Feet
{
   Name   Legs/feet
   Chance   14
   Layer   4
   Layer   3
   Layer   24
}

ArmorZone Neck
{
   Name   Neck
   Chance   7
   Layer   10
}

ArmorZone Hands
{
   Name   Hands
   Chance   7
   Layer   7
}
ROCKET SCIENCE

Re: GetConfigStringKeys() on elements with no key names

Posted: Fri May 05, 2006 4:43 pm
by tekproxy
tekproxy wrote:However, it works fine if I give the elements names.
Hmmm. There's no need to get mad. It's just sort of an odd behavior to only return ONE element. I'd rather it give an error or return all elements...

Posted: Fri May 05, 2006 5:06 pm
by Austin
Not mad, just being a smart-ass.

It just finds the first match. It isnt gonna return them all.
Likewise say you have four instances of

Elem MyElem
{
}
Elem MyElem
{
}

Itll give you the first one.

So... name the elems.

Posted: Fri May 05, 2006 6:00 pm
by tekproxy
It's nice to see you posting again. :)

Posted: Fri May 05, 2006 6:49 pm
by Austin
Laws of social-physics (taken from dieselsweeties.com)

Addition can be neither created nor destroyed, only changed.

My beer funds are a bit low ¬_¬

Posted: Fri May 05, 2006 7:55 pm
by tekproxy
Maybe if they didn't end all days with "y", eh? I think if you took beer out of the world, 80-90% of all open source projects would be finished in about a week.

Posted: Sun May 07, 2006 3:40 pm
by Austin
There is so much truth in that post.. its scary :-P