File to map

From Kolmafia
Revision as of 05:23, 10 September 2009 by imported>Out of practice (Explaination and example of file_to_map() function. Example is particularly polished, if I do say so myself.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

boolean file_to_map( string file_name , aggregate map )

boolean file_to_map( string file_name , aggregate map , boolean condition_for_loading )


Loads a map from a saved file, and returns a boolean of the operation's success. While all that is required to run it is the saved file's name, and a compatible map, it can also contain a conditional that must evaluate as true to execute the file-map load.

For example:

#Loading (and displaying) an arbitrary map from a file
string[int] favorite_things;
boolean load_success = file_to_map( "ponies_and_candycanes.txt" , favorite_things );

if( load_success == true )
{
   print( "All of your favorite things have come here to KoLMafia to play! Yay! There's:" , "#FF6666" );
   for cycle from 1 upto (count(favorite_things)-1)
   {
      print( ""+favorite_things[cycle]+", and..." , "#FF00CC" );
   }
   print( ""+favorite_things[count(favorite_things)]+", oh my!" , "#FF00CC" );
}
else
{
   print( "Your favorite things failed to load. Apparently they don't love you back." , "Red" );
}

With the saved file "ponies_and_candycanes.txt" being:

1      Sunshine
2      Cabbage
3      Computers
4      The Sound of Music
5      Paddington Bear

Would yield an output of:

All of your favorite things have come here to KoLMafia to play! Yay! There's:
Sunshine, and...
Cabbage, and...
Computers, and...
The Sound of Music, and...
Paddington Bear, oh my!