Difference between revisions of "Import"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
m
imported>PhilmASTErpLus
(Properly formatted code with Template:CodeSample. Also added some fuzzy information about main(), please look at talk page.)
Line 1: Line 1:
 
'''import <filename>'''
 
'''import <filename>'''
<br />'''Import''' is a command that is used to import (hence the name) an entire file's contents into the file in which '''import''' is called.
 
  
<p>Example:
+
'''Import''' is a command that is used to import (hence the name) an entire file's contents into the file in which '''import''' is called. "Nested" imports are possible; a script that is being imported may import another script. If a single file is imported more than once, KoLmafia will automatically avoid function name collisions. Note that when a script that has a <code>main()</code> function is imported into another script with another <code>main()</code> function, only the top-level <code>main()</code> is executed, and all <code>main()</code> functions from imported scripts will be ignored.
<pre># snippet from my aftercore.ash file
+
 
 +
==Example==
 +
 
 +
{{CodeSample|code=<syntaxhighlight>
 +
# snippet from my aftercore.ash file
 
import <aftercore_config.ash> // import the configuration file (loaded with variables) into the script
 
import <aftercore_config.ash> // import the configuration file (loaded with variables) into the script
 
import <aftercore_bounty.ash> // import bounty functionality (loaded with functions) into the script
 
import <aftercore_bounty.ash> // import bounty functionality (loaded with functions) into the script
Line 11: Line 14:
 
boolean using_upcs_curr = false;
 
boolean using_upcs_curr = false;
  
# ...</pre></p>
+
# ...
 +
</syntaxhighlight>}}
 
{{Format}}
 
{{Format}}

Revision as of 17:34, 28 June 2010

import <filename>

Import is a command that is used to import (hence the name) an entire file's contents into the file in which import is called. "Nested" imports are possible; a script that is being imported may import another script. If a single file is imported more than once, KoLmafia will automatically avoid function name collisions. Note that when a script that has a main() function is imported into another script with another main() function, only the top-level main() is executed, and all main() functions from imported scripts will be ignored.

Example

# snippet from my aftercore.ash file
import <aftercore_config.ash> // import the configuration file (loaded with variables) into the script
import <aftercore_bounty.ash> // import bounty functionality (loaded with functions) into the script

int first_meat = my_meat();
int first_advs = my_adventures();
boolean using_upcs_curr = false;

# ...

Formatting Needed