Needing help with writing a script

Nera

New member
Greetings, KOLMafia friends!

I have been attempting to write a script that triggers when the user hits 0 adventures, and then triggers an outfit change to a custom outfit.

I have been unable to figure out how to do this, and would like some pointers.

How do you get KOLMafia to detect when there are no more adventures left? This has been my biggest problem.

This is also my first time scripting with KOLMafia, so I am inexperienced with it. If any of you know of a script that already does this, let me know so I am not wasting time making something that already exists. Thank you! :cool:
 

Winterbay

Active member
In order to check for 0 adventures you can do:
Code:
if (my_adventures() == 0) {
   code to do stuff
}

After that you can do the things you want in the {}-area.
 

slyz

Developer
You can configure Mafia to automatically run some scripts at different occasions. The Mafia Wiki has a list of those occasions here: http://wiki.kolmafia.us/index.php?title=Miscellaneous_ASH_Features#Additional_Script_Uses

To specify the script you want to run, go to Preferences -> Automation.

In your case, I guess you want an After Adventure script. Mafia will execute your After Adventure script after each adventure when you are automating your turns, and also after each manual adventure if "Run afterAdventureScript after manual adventures" is checked in the Preferences.

You will want your script to exit without doing anything if you have more than 0 adventures left. The following snippet will make your script exit if you have more than 0 adventures:
PHP:
if ( my_adventures() > 0 ) exit;
To learn about the ASH scripting language, I suggest you read the ASH For Beginners page.

This is a very nice community for people willing to learn, so if you are stuck on something, or if you want someone to give advice on any work in progress, simply post here.
 
Last edited:

Paragon

Member
I don't know what you are trying to do, but you can set a log out script to run when you log out rather then when you run out of adventures.
 

ereinion

Member
In order to get it to check if you have no adventures left after every adventure spent, you'll either have to set it as your after your afterAdventureScript (this can either be done under preferences->automation, or in the cli) or use some kind of unconditional trigger in your moods to call it when you have no adventures left. If you do the first, you put the check Winterbay posted around the code you want the run, if you do the second I'd guess you put nothing in the "check for"-box and something like
Code:
ashq if(my_adventures()<= 0) { cli_execute("call myscript.ash") }
in the command box. I'm not all that familiar with unconditional triggers though, so for all I know that may put mafia into an infinite loop unless the script increases your number of adventures or something, someone more familiar with moods can probably provide more assistance if you decide to go that route.
 

Bale

Minion
What the last couple of people have tried to say is that if you tell us what you are trying to accomplish, they can probably give you better advice. There are just so many ways to do things in KoLmafia that they want to help you chose the best option. slyz wasn't kidding about this community being eager to give advice. ;)
 

HasteBro

Member
Also, it might be important to note what type of script you're trying to do, there being ASH scripts and CLI command scripts. Both are capable of accomplishing what you want, with ASH being the more complex of the two, in terms of what you can do, while CLI command script is an automated command input script. You never mentioned which you're trying to make.
 
Top