File to map: Difference between revisions
Jump to navigation
Jump to search
imported>Out of practice Explaination and example of file_to_map() function. Example is particularly polished, if I do say so myself. |
imported>Out of practice m Pseudo-Intellectual Pedantry |
||
Line 4: | Line 4: | ||
Loads a map from a saved file, and returns a [[boolean]] of the operation's success. While all that is required to | 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. | ||
<p>For example:<pre>#Loading (and displaying) an arbitrary map from a file | <p>For example:<pre>#Loading (and displaying) an arbitrary map from a file |
Revision as of 05:44, 10 September 2009
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 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.
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!