external files quick question

scypher999

New member
Hi,
I'm new to KOLMafia and was just wondering if it is possible to read/write from external files and if so how would one go about doing this, especially writing. i am writing a script for auto-completing a quest and i wish to write to an external file to keep track of which parts of a quest have been completed (in case a quest isn't completely fully in one day). Thanks in advance for any help.
 

jasonharper

Developer
Use file_to_map() and map_to_file(). They require that the data be in the form of a map, but you can always create a map with a single entry that's your data, in whatever format.

You can also store strings in the user preferences via get_property() and set_property(). I would suggest using preference names that include either your name or the name of your script, to minimize the chance of collision with another script's preferences, or those of mafia itself.
 

Bale

Minion
Just to help you out, here's an example of how map files work:

Code:
record res_info {
	int minhp;
	int maxhp;
	int minmp;
	int maxmp;
	boolean combat;
};

res_info [item] heal;

heal[ $item[plump juicy grub] ].minhp = 90;
heal[ $item[plump juicy grub] ].maxhp = 100;
heal[ $item[plump juicy grub] ].minmp = 0;
heal[ $item[plump juicy grub] ].maxmp = 0;
heal[ $item[plump juicy grub] ].combat = false;
heal[ $item[Delicious shimmering moth] ].minhp = 0;
heal[ $item[Delicious shimmering moth] ].maxhp = 0;
heal[ $item[Delicious shimmering moth] ].minmp = 30;
heal[ $item[Delicious shimmering moth] ].maxmp = 40;
heal[ $item[Delicious shimmering moth] ].combat = false;
heal[ $item[bottle of Vangoghbitussin] ].minhp = 100;
heal[ $item[bottle of Vangoghbitussin] ].maxhp = 100;
heal[ $item[bottle of Vangoghbitussin] ].minmp = 100;
heal[ $item[bottle of Vangoghbitussin] ].maxmp = 100;
heal[ $item[bottle of Vangoghbitussin] ].combat = false;
heal[ $item[Nardz energy beverage] ].maxhp = 0;
heal[ $item[Nardz energy beverage] ].minmp = 50;
heal[ $item[Nardz energy beverage] ].maxmp = 80;
heal[ $item[Nardz energy beverage] ].combat = false;
heal[ $item[Knob Goblin seltzer] ].minhp = 0;
heal[ $item[Knob Goblin seltzer] ].maxhp = 0;
heal[ $item[Knob Goblin seltzer] ].minmp = 8;
heal[ $item[Knob Goblin seltzer] ].maxmp = 12;
heal[ $item[Knob Goblin seltzer] ].combat = true;
heal[ $item[black cherry soda] ].minhp = 0;
heal[ $item[black cherry soda] ].maxhp = 0;
heal[ $item[black cherry soda] ].minmp = 8;
heal[ $item[black cherry soda] ].maxmp = 11;
heal[ $item[black cherry soda] ].combat = false;

map_to_file(heal,"recoveryScript_map.txt");
print("Restoratives map written.");

That creates a map file, then to read the file you can do this:
Code:
record restorative_info {
	int minhp;
	int maxhp;
	int minmp;
	int maxmp;
	boolean combat;
};
restorative_info [item] heal;

void restore_values() {
	if (!file_to_map("recoveryScript_map.txt",heal))
		abort("Restorative data is corrupted or missing. Troublesome!");
	if (count (heal) == 0)
		abort("Restorative data is corrupted or missing. Troublesome!");
}

You can put the map file in either your /scripts or /data directory. Mafia will automatically find it in either location.
 
Top