How do you write an ASH file?

Mystia

Member
I'm looking over the basic commands for scripting and I want to give it a shot.

What program do I use to start writing? Is there a command in KoLMafia that brings up an empty notepad that will save things in .ash format for you?

Do you just write it in a notepad and change the file extention to .ash?
 

asturia

Minion
I'm looking over the basic commands for scripting and I want to give it a shot.

What program do I use to start writing? Is there a command in KoLMafia that brings up an empty notepad that will save things in .ash format for you?

Do you just write it in a notepad and change the file extention to .ash?
I use notepad++ to edit my ash scripts.
I have a syntax file so that it assigns colors to the scripts.
I'll attach it here.
But seriously, don't use notepad, use Notepad++
 

Mystia

Member
I don't have any characters with adventures I can test this on, but are there any major errors with this script? If I saved it as .ash and executed it, would it work?

{
cli_execute("acquire milk of magnesium")
cli_execute("acquire 15 twinkly wad")
cli_execute("use 15 twinkly wad")
cli_execute("acquire 19 blackberry schnapps")
cli_execute("drink 19 blackberry schnapps")
cli_execute("acquire 3 hi mein")
cli_execute("use 1 milk of magnesium")
cli_execute("eat 3 hi mein")
cli_execute("outfit Castle")
cli_execute("familiar leprechaun")
cli_execute("equip meat detector")
cli_execute("adventure * Giant's Castle")
cli_execute("autosell * heavy D, * Original G, * disturbing fanfic, * furry fur, * wolf mask, * awful poetry journal, * thin black candle, * chaos butterfly, * plot hole, * probability potion, * procrastination potion, * angry farmer candy, * giant needle, * Mick's IcyVapoHotness Rub, * rave whistle")
cli_execute("acquire 1 roll in the hay")
cli_execute("drink 1 roll in the hay")
cli_execute("use * Warm Subject gift certificate");
}
 

lostcalpolydude

Developer
Staff member
If everything is going to be a cli_execute command, why not just make it a .txt and drop those? Easier growth later?
 

Mystia

Member
I just started scripting today. cli_execute is just what I'm starting with.

I want to make sure I'm on the right track before adding things to it.
 

Bale

Minion
Notepad++ is free and easy to download. I'm attching the syntax highlighting for ash to this post. Unzip it and place it in the same directory as notepad++.exe

No, that script would not work. You forgot to put semi-colons at the end of each line. You also did not specify which hi mein to eat. If you fixed that it would work, but this would be better:

Code:
retrieve_item(1, $item[milk of magnesium])
retrieve_item(15, $item[twinkly wad]);
use(15, $item[twinkly wad]);
retrieve_item(19, $item[blackberry schnapps]);
drink(19, $item[blackberry schnapps]);
use(1, $item[milk of magnesium]);
cli_execute("cheapest hi mein; acquire 3 it; eat 3 it;");
outfit("Castle");
use_familiar($familiar[leprechaun]);
equip($slot[familiar], familiar_equipment(my_familiar()));
adventure(my_adventures(), $location[Giant's Castle]);
batch_open();  // This tells mafia that there will be a lot of autoselling, malling or other batch activity, so it should save them up.
int saleprice = 0;
foreach it in $items[heavy D, Original G, disturbing fanfic, furry fur, wolf mask, awful poetry journal, thin black candle, 
  chaos butterfly, plot hole, probability potion, procrastination potion, angry farmer candy, giant needle, Mick's IcyVapoHotness Rub, 
  rave whistle] {
	autosell(item_amount(it), it);
	saleprice = item_amount(it) * autosell_price(it) + saleprice;
}
batch_close();  // Now it executes all recorded batch ativitites in groups of 11 at a time.
print("autosold trash for "+ saleprice +" meat.", "blue");
retrieve_item(1, $item[roll in the hay]);
drink(1, $item[roll in the hay]);
use(item_amount($item[Warm Subject gift certificate]), $item[Warm Subject gift certificate]);

Hopefully by comparing my ash to your cli script, you can learn a lot about ash.
 

Attachments

  • userDefineLang.zip
    2.2 KB · Views: 547
Last edited:

NitraMo

New member
Regarding the userDefineLang.xml file I had some trouble locating where to put it, same folder as notepad++.exe didn't work. Some internet searching told me to put it at %APPDATA%/Notepad++ instead, which worked for me.
I assume the location varies depending on operating system and settings used at install.
 

Mystia

Member
Thanks, Bale. That definitely helped me pick up on some of the coding.

Now I'm wondering how to work if/then strings, particularly, with comparing cheapest mall prices and letting the cost of the item determine whether or not it executes the script based on the mall price.

Are there more basic scripts out there I can glean information from, like the one you posted here?


edit: grammar fix
 

Bale

Minion
There are tons of scripts you can learn from. Just look around. Even if a script seems too large to get a grasp on, perhaps some part of it will help you.

Also, when I'm in the mood I produce examples to order. I think you could learn from something I posted yesterday here. I'll just copy-paste it for convenience.

Code:
void cheapest_first (item [int] commodity) {
	int [item] price;
	foreach key in commodity
		if(historical_age(commodity[key]) >0.5)
			price[ commodity[key] ] = mall_price(commodity[key]);
		else
			price[ commodity[key] ] = historical_price(commodity[key]);
	sort commodity by price[value];
}

item cheapest_shc() {
	item [int] drinkies;
	foreach key in $items[Neuromancer, stratocaster, Mon Tiki, teqiwila slammer, Divine, Gordon Bennett, gimlet, yellow brick road,
	  mandarina colada, tangarita, Mae West, prussian cathouse]
		drinkies[count(drinkies)] = key;
	cheapest_first(drinkies);
	return drinkies[0];
}

void main() {
	print("Cheapest Superhuman Cocktail is: "+ cheapest_shc());
}

That's obviously a bit more complicated than the earlier script. It makes use of maps to create a list of all supercocks so that it can order them from cheapest to most expensive. I'm not really sure what you're trying to do exactly, but if you need explanations of any part of the above script let me know. If you want to do something entirely different, I'll probably give you some tips about that also.
 

Winterbay

Active member
Since there are now some new ash-commands that are not in the file will there be coming some updates? I'm mainly thinking of item_drops_array and the new Crown of Throne-commands.

Apart from that it's a wonderful thing :)
I guess that the "can't really see where a string starts and ends when spaces are omitted" is a Notepad++ thing and not due to this file. Such as
Code:
print("Considering "+f+" versus "+g);

where it fails to note the beginning of the 2nd string and thus everything after the last " turns orange...
 

Grotfang

Developer
That's a notepad++ issue, yes. The other issue I have now and again is notepad++ doesn't recognise escaped characters, so if I'm matching a string with " in it, it has the same effect.

An easy way to limit the effect this will have is to add a commented out " to the end of the line:

Code:
#"

As for changing the xml... you could always do it yourself. For windows users, go to the directory that your AppData is stored in. For me, this is:

Code:
C:\Users\Ben\AppData\Roaming\Notepad++

Open up userDefineLang.xml in notepad++ (or similar) and look for the line that starts:

Code:
<Keywords name="Words4">

This line/section are functions. Words3 are control flow, words2 are assigned datatypes and words1 are (I'm not sure of the proper title, but a description will do) the operators that indicate which list for mafia to use to check through.

To add new functions, simply go to Words4 and type them in anywhere along that line, remembering to include underscores where necessary and exclude parentheses and parameters.

EDIT:

Figured I'd add the following functions. These are all the functions that showed up as being added using matt.chugg's search thingy (searching under "ASH") that aren't already there. Let me know if I've missed any:

Code:
my_enthroned_familiar
enthrone_familiar
item_drops_array
to_element
form_fields
 

Attachments

  • userDefineLang.zip
    2.2 KB · Views: 48
Last edited:

Winterbay

Active member
I've added the item_drops_array myself, but thought that since the guide to programming in ASH on the wiki links to this thread it would be good to have it uptodate so to say.

Also: if you run a portable installation (i.e. on a memory stick) then you have to put the xml-file in the installation directory.
 

heeheehee

Developer
Staff member
Hmm. I took a look (for once) at Notepad++'s very basic GUI (View => User-defined Dialogue) for creating a user-defined language, and what do you know, there's a checkbox for enabling escaping characters. I also added [] as quote-like, which might be useful. (e.g. $skill[The Ode to Booze] will no longer have "to" pinkified.)
 

Bale

Minion
Hmm. I took a look (for once) at Notepad++'s very basic GUI (View => User-defined Dialogue) for creating a user-defined language, and what do you know, there's a checkbox for enabling escaping characters.
Wonderful! that makes things so much nicer. Added it to my ash definition.

I also added [] as quote-like, which might be useful. (e.g. $skill[The Ode to Booze] will no longer have "to" pinkified.)
Not so good because it messes with maps a bit since they also use those brackets. When a map contains a constant like $item[Knob Goblin elite helm], I want $item to be highlighted.
 

StDoodle

Minion
Been a while since I poked at it, but I think you could separately set $item[, $familiar[, etc as start-of-quote delimiters. Maybe.
 

heeheehee

Developer
Staff member
Oh, and one more thing -- apparently the actual folding of functions doesn't appear if you use Bale's userDefineLang because { and } are also considered operators. Remove those from that list if desired.

Also, the easiest way (for me) to set $item[ and co. as start-of-quote delimiters was just to make one that went from $ to ].

Edit: Auto-completion! (Add the attached file in the directory YOUR_NPP_DIR\plugins\APIs where YOUR_NPP_DIR is the directory in which you installed Notepad++. Note that the extension of api file is xml.)
 

Attachments

  • ASH.zip
    1.7 KB · Views: 60
Last edited:

philmasterplus

Active member
Revised Syntax Highlighting File for Notepad++

I downloaded Bale's syntax highlighter file for notepad++ and fixed some problems, as well as tweaking the style to suit my taste.

Syntax issues:
  • Added import
  • Added %&|^ to the list of operators and removed \{}
  • Added \ as escape character.
  • Added single-quotes as strings.

Visibility tweaks:
  • Numbers are now displayed in brown.
  • Operators are now gray, as well as bold to improve visibility.
  • Strings were changed from orange to purple, and are no longer italicized.
  • Comments were changed from lime to green.

How to install:
Copy the userDefineLang.xml to the directory where notepad++.exe is in, most likely C:\Program Files\Notepad++\.

Customization:
You can access Notepad++'s custom syntax editor by selecting "View > User Defined Dialog..." from the top menu.

Notes for people trying to install heeheehee's autocomplete file above
Remember, the autocomplete file name (which is ASH.xml in the zip file) must be renamed to match the language name specified in the syntax highlighter file, which in this case would be KoLmafia ASH.xml

Thanks to Bale for doing most of the work in the first place.

/necro

Edit: dangit, using / and * as operators makes Notepad++ ignore C-style comments. There seems to be no definitive fix for this other than omitting these from the operator list--which wouldn't be a issue anyway if you add spaces around them, like this:
PHP:
float result = value1 / value2
 

Attachments

  • userDefineLang_p.zip
    2.2 KB · Views: 91
Last edited:
Top