File to map: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
mNo edit summary
imported>Jasonharper
m What is "has not been initialized" supposed to mean?
Line 23: Line 23:
parameter1={{Param|string|file_to_load}}|
parameter1={{Param|string|file_to_load}}|
parameter2={{Param|aggregate|map_to_fill}}|
parameter2={{Param|aggregate|map_to_fill}}|
parameter3={{Param|boolean|condition}}|
parameter3={{Param|boolean|compact}}|
p1desc={{Pspan|file_to_load}} is the filename to load from|
p1desc={{Pspan|file_to_load}} is the filename to load from|
p2desc={{Pspan|map_to_fill}} is the map to populate with data|
p2desc={{Pspan|map_to_fill}} is the map to populate with data|
p3desc={{Pspan|condition}} is an (optional) condition that must be met for the function to act|
p3desc={{Pspan|compact}} is an (optional) flag; if omitted or true, records that do not contain any aggregate values are expected to be written on a single line, rather that one line per field.|
}}|
}}|


function_description=Loads data to the {{pspan|map_to_fill}} from a saved {{pspan|file_to_load}} in your KoLmafia "data" directory. If {{pspan|condition}} is supplied, it must evalute to true in order for the function to proceed. This function returns the operation's success (if {{pspan|condition}} is supplied, and evaluates to false, this function returns true). If {{pspan|map_to_fill}} has not been initialized, this function will abort (as oppossed to returning false).|
function_description=Loads data to the {{pspan|map_to_fill}} from a saved {{pspan|file_to_load}} in your KoLmafia "data" or "scripts" directory. The {{pspan|compact}} parameter is not needed unless you specified it in the [[map_to_file|map_to_file()]] call that originally generated the file, in which case the values must match. This function returns the operation's success. If {{pspan|map_to_fill}} has not been initialized, this function will abort (as oppossed to returning false).|


code1={{CodeSample|
code1={{CodeSample|

Revision as of 04:43, 11 March 2010

Function Syntax

boolean file_to_map(string file_to_load ,aggregate map_to_fill )

boolean file_to_map(string file_to_load ,aggregate map_to_fill ,boolean compact )

  • file_to_load is the filename to load from
  • map_to_fill is the map to populate with data
  • compact is an (optional) flag; if omitted or true, records that do not contain any aggregate values are expected to be written on a single line, rather that one line per field.

Loads data to the map_to_fill from a saved file_to_load in your KoLmafia "data" or "scripts" directory. The compact parameter is not needed unless you specified it in the map_to_file() call that originally generated the file, in which case the values must match. This function returns the operation's success. If map_to_fill has not been initialized, this function will abort (as oppossed to returning false).

Code Sample

This sample loads a simple map that includes item names keyed by a number.

string [int] my_list;
file_to_map( "SavedList.txt" , my_list);
for i from 0 to (count(my_list) - 1) {
   print( "At index: " + i + " We find: " + my_list[i] );
}

If the file "SavedList.txt" had the following:

0	StDoodle
1	Grotfang

Then the results would be:

At index: 0 We find: StDoodle
At index: 1 We find: Grotfang

See Also

map_to_file()