count() issues?

gemelli

Member
Hola!

In the public 11.0 build, I noticed some problems using the count() function in ASH.

Specifically, consider the following code:

Code:
void main() {

	location lLast = my_location();
	print("Last location: "+location_to_string(lLast));
	monster [int] mMonstaz = get_monsters(lLast);

	int iHowmany = count(mMonstaz);

	foreach key in mMonstaz
	{
		monster thisone = mMonstaz[key];
		string heyman = monster_to_string(thisone);
		print("Monster " + heyman);
	}

}

As written, the function will not run at all in 11.0.  However, if you comment out the line:

Code:
// int iHowmany = count(mMonstaz);

... the script runs fine.  Was count() or get_monsters() changed for this release?

Danke!

EDIT: Updated to note that count() works fine with a map of type string [int] my_map.  It appears to be the monster map that's causing problems.

EDIT 2: For some reason, I am no longer seeing this error.  The above code works fine.  Not sure why it was giving me problems yesterday but not today, but I don't think it's worth throwing lots of brain cycles at the problem :)
Well, the problem is back, but not consistently.  Sometimes my scripts using count() with ASH-specific data types work, but sometimes they don't.  Here's an excerpt from my debug log, posted in hopes that it might help narrow down the cause:

UNEXPECTED ERROR.  Debug log printed.
net.sourceforge.kolmafia.KoLmafiaASH$AdvancedScriptException: Illegal parameter #1 for function count, got skill [int], need string [2] (InterStasis-v4.ash.txt, line 430)

This was for a map I defined as skill [int] skillkey ... the script died when it got to the line:

numSkills=count(skillkey);

Any ideas?

EDIT: I think I've figured it out. The first time I call count() during an ASH session seems to permanently associate count with the type of map sent to it. If I then call count() with a map of a different type later in the same function -- or even in a different function used within the same Mafia session -- the function fails. So given the following code:

Code:
void main() {

	monster[int] foo;
	foo[0]=$monster[gargantulihc];
	foo[1]=$monster[quiet healer];

	print("Foo has "+count(foo)+" items.");

	string [int] bar;
	bar[0]="Ya dig";
	bar[1]="Sho nuff";
	
	print("Bar has "+count(bar)+" items.");

}
The function will fail for me unless I comment out the second print line. Does that make sense?

I'd be most grateful if someone could try to duplicate this on their own machine. I'm having one of those "maybe it's just me" moments ...
 
Top