File to map: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Out of practice
m Pseudo-Intellectual Pedantry
imported>Out of practice
Upgrades!
Line 1: Line 1:
'''[[boolean]] file_to_map( [[string]] file_name , [[aggregate]] map )'''
'''[[boolean]] file_to_map( [[string]] file_to_load , [[aggregate]] map_to_fill )'''


'''[[boolean]] file_to_map( [[string]] file_name , [[aggregate]] map , [[boolean]] condition_for_loading )'''
'''[[boolean]] file_to_map( [[string]] file_to_load , [[aggregate]] map_to_fill , [[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 execute file_to_map() 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.


Loads a map from a saved file, and returns a [[boolean]] of the operation's success. While all that is required to execute file_to_map() 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.
If file_to_map() is called from within a script, it will automatically load the specified filename from the KoLMafia\Scripts\ directory ([[map_to_file()]]'s automatic in-script save location). If file_to_map() is called from within a library function, it will load the specified filename from the KoLMafia\Data\ directory (the save location of [[map_to_file()]] when run within a library function).


<p>For example:<pre>#Loading (and displaying) an arbitrary map from a file
 
<p>''A script example of loading a pre-defined map from a file:''<pre>#Loading (and displaying) an arbitrary map from a file
string[int] favorite_things;
string[int] favorite_things;
boolean load_success = file_to_map( "ponies_and_candycanes.txt" , favorite_things );


if( load_success == true )
if( file_to_map( "ponies_and_candycanes.txt" , favorite_things ) == true )
{
{
   print( "All of your favorite things have come here to KoLMafia to play! Yay! There's:" , "#FF6666" );
   print( "All of your favorite things have come here to KoLMafia to play! Yay! There's:" , "#FF6666" );
Line 23: Line 24:
   print( "Your favorite things failed to load. Apparently they don't love you back." , "Red" );
   print( "Your favorite things failed to load. Apparently they don't love you back." , "Red" );
}</pre></p>
}</pre></p>
 
<p>Would obviously produce a different output depending on what you had saved in the list. For example, were the contents of "ponies_and_candycanes.txt":''<pre>1      Sunshine
<p>With the saved file "ponies_and_candycanes.txt" being:<pre>1      Sunshine
2      Cabbage
2      Cabbage
3      Computers
3      Computers
Line 30: Line 30:
5      Paddington Bear</pre></p>
5      Paddington Bear</pre></p>


<p>Would yield an output of:<pre>All of your favorite things have come here to KoLMafia to play! Yay! There's:
<p>''Would yield an output of:''<pre>All of your favorite things have come here to KoLMafia to play! Yay! There's:
Sunshine, and...
Sunshine, and...
Cabbage, and...
Cabbage, and...

Revision as of 07:18, 10 September 2009

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 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 execute file_to_map() 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.

If file_to_map() is called from within a script, it will automatically load the specified filename from the KoLMafia\Scripts\ directory (map_to_file()'s automatic in-script save location). If file_to_map() is called from within a library function, it will load the specified filename from the KoLMafia\Data\ directory (the save location of map_to_file() when run within a library function).


A script example of loading a pre-defined map from a file:

#Loading (and displaying) an arbitrary map from a file
string[int] favorite_things;

if( file_to_map( "ponies_and_candycanes.txt" , favorite_things ) == 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" );
}

Would obviously produce a different output depending on what you had saved in the list. For example, were the contents of "ponies_and_candycanes.txt":

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!