<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.kolmafia.us/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=203.173.138.156</id>
	<title>Kolmafia - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kolmafia.us/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=203.173.138.156"/>
	<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Special:Contributions/203.173.138.156"/>
	<updated>2026-04-25T03:49:49Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=ASH_For_Beginners&amp;diff=6326</id>
		<title>ASH For Beginners</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=ASH_For_Beginners&amp;diff=6326"/>
		<updated>2010-06-02T07:27:14Z</updated>

		<summary type="html">&lt;p&gt;203.173.138.156: /* Mac */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOCright}}&lt;br /&gt;
==File Editing==&lt;br /&gt;
To create and edit ASH scripts, you need a text editing program that doesn&#039;t automatically add line-breaks for word wrapping.&lt;br /&gt;
&lt;br /&gt;
===Mac===&lt;br /&gt;
While the built in editor TextEdit will work fine (as long as you remember to write only in plaintext), [http://www.barebones.com/products/textwrangler/ TextWrangler] is a much more powerful tool. It may not be designed for ASH scripting specifically, but it was written for a similar purpose.&lt;br /&gt;
&lt;br /&gt;
===Linux===&lt;br /&gt;
If you use Linux, you probably already know about the options available for text editing. Emacs, Vi, etc. are all fine for creating ASH scripts.&lt;br /&gt;
&lt;br /&gt;
===Windows===&lt;br /&gt;
Windows users beware; using Microsoft Word to create ASH files will lead to no end of headaches! The built-in program notepad will work, as can wordpad when configured with the option &amp;quot;No Wrap&amp;quot; for text. However, having a program that can handle syntax-highlighting can be very beneficial. Many scripters recommend [http://notepad-plus.sourceforge.net/uk/site.htm Notepad++] for ASH (and other programmatic) scripting. In this case, it&#039;s also beneficial to have a style configuration that works well with ASH, and one example can be found [http://kolmafia.us/showthread.php?3164-How-do-you-write-an-ASH-file&amp;amp;p=21567&amp;amp;viewfull=1#post21567 here].&lt;br /&gt;
&lt;br /&gt;
==Saving==&lt;br /&gt;
ASH scripts need to be saved with the file extension &amp;quot;.ash&amp;quot; to be properly recognized by KoLmafia. If you&#039;re using a built-in text editor on a Windows machine, it may automatically save your files with the &amp;quot;.txt&amp;quot; extension by default. (So you may end up with a file called &amp;quot;script.ash.txt&amp;quot; instead of the desired &amp;quot;script.ash&amp;quot;.) One way around this on Windows that usually works is to put quotes around the file name when you save it, including the extension.&lt;br /&gt;
&lt;br /&gt;
Most advanced text editors (such as Notepad++) will save files as specified, without the need for the quotes-trick.&lt;br /&gt;
&lt;br /&gt;
Most files should be saved in the &amp;quot;scripts&amp;quot; directory, which is located by default at the same directory level as the KoLmafia .jar or .exe file on Windows. You can also create a sub-directory under &amp;quot;scripts,&amp;quot; and it will be listed in KoLmafia&#039;s Scripts Menu.&lt;br /&gt;
&lt;br /&gt;
Relay browser scripts are the exception to the rule: they must be saved in the &amp;quot;relay&amp;quot; directory. Relay browser overrides need to be saved in the top level of &amp;quot;relay,&amp;quot; and must be named the same as the page they will override, except with an &amp;quot;.ash&amp;quot; extension. For example, to override &amp;quot;charpane.php&amp;quot; your script would need to be named &amp;quot;charpane.ash&amp;quot;. For user-interface scripts, the script name needs to start with &amp;quot;relay_&amp;quot; and end with &amp;quot;.ash&amp;quot;. These scripts must also be saved in the top-level of the &amp;quot;relay&amp;quot; directory.&lt;br /&gt;
&lt;br /&gt;
==Programming==&lt;br /&gt;
You should first read through the various pages listed under &amp;quot;LANGUAGE CONVENTIONS&amp;quot; on the [[Main Page]]. One should also be aware that, with the exception of [[Control Structures]], all ASH commands need to end with a semi-colon.&lt;br /&gt;
&lt;br /&gt;
===Variables===&lt;br /&gt;
Variables are used to hold information that you need to access multiple times. They must be declared before they can be used, by specifying the [[Datatype Constants|Datatype Constant]] that they will hold, followed by the variable name.&lt;br /&gt;
{{CodeSample|description=For example:|code=&amp;lt;syntaxhighlight&amp;gt;int count;&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
would declare a variable named &amp;quot;count&amp;quot; of an integer type. You can also set the initial value of a variable on the same line it is declared.&lt;br /&gt;
{{CodeSample|description=For example:|code=&amp;lt;syntaxhighlight&amp;gt;int count = 6;&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
would declare the variable &amp;quot;count&amp;quot; again, with an initial value of 6.&lt;br /&gt;
&lt;br /&gt;
Notice that you would not want to have both of the above lines in your script! Variables operate under what&#039;s referred to as their scope. In a nutshell, scope defines where a variables is accessible. Scope &amp;quot;cascades&amp;quot; down, similar to stylesheets for those familiar with web programming. A variable declared at the top-level of a script (a &amp;quot;global&amp;quot; variable), outside of any functions, will be accessible anywhere in your script, or in any other scripts that import it. A variable declared inside of a function will be accessible only inside that function (including inside of control structures), but is considered to not exist by other functions.&lt;br /&gt;
&lt;br /&gt;
Declaring a variable multiple times will generate an [[ASH Errors#Variable is already defined|error]]. Note that this only applies to variable with overlapping scope; if one function uses a variable named &amp;quot;bob&amp;quot; that is declared inside of the function, another function can declare another variable with the same name, even as a different datatype. However, the error will still occur if you have a globally-defined variable, and then declare a variable with the same name inside of a function (as their scopes overlap).&lt;br /&gt;
&lt;br /&gt;
===Functions===&lt;br /&gt;
Functions are groupings of operations that can be applied multiple times by referencing the function name. Basically, they avoid having to re-type the same code over and over. Many functions are built-in to KoLmafia, and examples can be found all over this wiki. It&#039;s also possible to write your own functions. To do so, you declare them similarly to a variable as above. However, a function can also have the datatype of &amp;quot;void,&amp;quot; which is not allowed for variables. A &amp;quot;void&amp;quot; function is one that does not return any value; it simply does what it&#039;s programmed to do and the rest of your program moves on, regardless of the results (unless of course an [[ASH Errors|error]] occurs, including a call to [[abort|abort()]].)&lt;br /&gt;
{{CodeSample|description=For example, this simple function will double an integer:|code=&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
int double_it(int value) {&lt;br /&gt;
   return 2 * value;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===String Concatenation===&lt;br /&gt;
The basics to string concatenation: &amp;quot;Hello&amp;quot; + &amp;quot;world&amp;quot; yields &amp;quot;Helloworld&amp;quot;. Likewise, variables can be strung together in this fashion. Unless the variables are both numbers (floats, booleans, or ints), they will be converted to strings, then concatenated.&lt;br /&gt;
Argh, me tired, finish later.&lt;br /&gt;
&lt;br /&gt;
[[Category:ASH Scripting]]&lt;/div&gt;</summary>
		<author><name>203.173.138.156</name></author>
	</entry>
</feed>