Maps only support primitive data types?

macman104

Member
I decided to begin work on a script that would determine how many days till stat days, and some other fun things, mainly for my own enjoyment, and because I wanted to keep playing around with maps and such. I tried to make the following script, but I get the message "Index type 'day' is not a primitive type (MoonTest.ash, line 7)". Can we not index by records like that? Do I just need to use a map like this instead of the record?
Code:
stat [string, string] moonList
I wanted to use the record, just because it was cleaner and easier to work with. Is this not possible, or am I missing something? I need to index by the days, and not by the stats since eventually, I'm also going to have moons in there that are indexed to a $stat[none] type as well...
Script:
Code:
record day
{
	string ronald;
	string grimace;
};

stat [day] moonList;

stat moxie = $stat[moxie];
stat muscle = $stat[muscle];
stat myst = $stat[mysticality];

day makeDay(String ronald, String grimace)
{
	day newDay;
	newDay.ronald = ronald;
	newDay.grimace = grimace;
	return newDay;
}

void main()
{
	moonList[makeDay("moon1.gif", "moon1.gif")] = moxie;
	moonList[makeDay("moon8.gif", "moon8.gif")] = moxie;
	moonList[makeDay("moon5.gif", "moon3.gif")] = myst;
	moonList[makeDay("moon5.gif", "moon7.gif")] = myst;
	moonList[makeDay("moon1.gif", "moon5.gif")] = muscle;
	moonList[makeDay("moon2.gif", "moon5.gif")] = muscle;

	map_to_file(moonList, "moonMap.txt");
}
 

holatuwol

Developer
With maps, you need some way of defining equality for values which are used as keys.  Since user-defined types have no such requirement, there's no way to sensibly use them as keys/indices into a map. Also, since it's relevant to your script, you might be interested in the stat_bonus_today and stat_bonus_tomorrow functions? o_0
 

macman104

Member
[quote author=holatuwol link=topic=972.msg4835#msg4835 date=1181729183]
With maps, you need some way of defining equality for values which are used as keys. Since user-defined types have no such requirement, there's no way to sensibly use them as keys/indices into a map. Also, since it's relevant to your script, you might be interested in the stat_bonus_today and stat_bonus_tomorrow functions? o_0[/quote]Yea, I'm aware of those functions. I'm just partially doing this as an exercise, and also because I...yea, I dunno. Lol. But that's fine, Maybe I'll just define a map for each moon, or something. I'll figure it out. Appreciate the explanation though...
 
Ronald and Grimace are based on the octal number system http://en.wikipedia.org/wiki/Octal and the stat days for them could be calculated just as easy, but here is what I came up with that does near the same thing in a similar way:

Code:
int [string] moon_to_int;

moon_to_int ["moon1.gif"] = 0;
moon_to_int ["moon2.gif"] = 1;
moon_to_int ["moon3.gif"] = 2;
moon_to_int ["moon4.gif"] = 3;
moon_to_int ["moon5.gif"] = 4;
moon_to_int ["moon6.gif"] = 5;
moon_to_int ["moon7.gif"] = 6;
moon_to_int ["moon8.gif"] = 7;

int packed_moons(int ronald, int grimace)
{
return ronald * 10 + grimace;
}

stat [int] moonList;

stat moxie = $stat[moxie];
stat muscle = $stat[muscle];
stat myst = $stat[mysticality];

void main()
{
moonList[packed_moons(moon_to_int["moon1.gif"], moon_to_int["moon1.gif"])] = moxie;
moonList[packed_moons(moon_to_int["moon8.gif"], moon_to_int["moon8.gif"])] = moxie;
moonList[packed_moons(moon_to_int["moon5.gif"], moon_to_int["moon3.gif"])] = myst;
moonList[packed_moons(moon_to_int["moon5.gif"], moon_to_int["moon7.gif"])] = myst;
moonList[packed_moons(moon_to_int["moon1.gif"], moon_to_int["moon5.gif"])] = muscle;
moonList[packed_moons(moon_to_int["moon2.gif"], moon_to_int["moon5.gif"])] = muscle;

	map_to_file(moonList, "moonMap.txt");
}

The code is untested.

In simple terms each day has a number from 0 to 77 skipping 8, 9, 18, 19, 28, 29, ....and so on
The number in the tens column represents ronald, in the ones column represents grimace. I don't know of any native support in kolmafia for the octal numbering system, but writing a minimal function set to work with octal numbers would be easy enough if any further need arises.
 
Top