Is there a way to call a script when adventure left is 10 or 0?

Question: Is there a way to call a script when adventure left is 10 or 0?

Not sure how to explain it, but when you have 10 adventure left, call a script like rollover.ash? Or see what else i need to do, like daily dungeon or something.
 

Theraze

Active member
Unconditional mood, in the mood start with a check if my_adventures() == 10 (or 0)? Could also do that as a Between Battle Script, but the mood has a higher chance of working with manual adventuring, since you can turn on running moods during manual and can't turn on BBS with manual.
 
After setting Unconditional trigger, when I try to input Check For: if my_adventures() == 0, it will just blank out what i typed after I click on the Command box to input my command. Is there something Im missing? Clicking on 'add entry' button also deletes my command.
 

Bale

Minion
Is there something Im missing?

Yes. You don't use the "check for" box if the trigger is unconditional.

Just put ashq if(my_adventures() == 10) cli_execute("call script.ash") in the command box.

Actually, I'd rather check if <= 10, but then script.ash would need a check to verify that it wasn't executing more frequently than it should.
 
Last edited:

Theraze

Active member
Not a problem... just be warned that as its name suggests, it will happily overdrink without further warning. :)
 

Bale

Minion
Is there a way to change 'if' to 'when'?

That's the sort of question that makes me ask what you're doing. I'm not sure what the difference is between 'if' and 'when' so you'd need to explain a lot more before you can get a meaningful answer.
 

fronobulax

Developer
Staff member
That's the sort of question that makes me ask what you're doing. I'm not sure what the difference is between 'if' and 'when' so you'd need to explain a lot more before you can get a meaningful answer.

+1 on the request for more information.

That said, "if' is often used in cases where something may or not happen. "when" is used with the implicit assumption that something will happen. The construct occurs a lot with Feature Requests. Someone makes FR. Someone responds with a comment about the implications of the FR, if it is implemented and then someone eventually talks about when it is implemented. If the person using "when" writes code it is an implicit agreement to make the patch otherwise is is s subtle endorsement of the FR.

In the context of the oneliner, if will trigger if there are exactly 10 adventures and fail to trigger everywhere else. You noted that it is more robust to trigger on <= 10 but then the trigger action has to do the right thing when called multiple times. A when construct would be based upon the assumption that there are currently more than 10 adventures and would trigger as they decrement through 10. The distinction is in how the code is conceptualized and organized and ultimately how robust it is. If the code should "Do the Right Thing" no matter how many adventures there are then the difference between if and when becomes moot but if i am being lazy and not writing bullet proof code then it might matter.
 
Thank you very much for your replies!
The extra question is just my curiousity speaking, as the unconditional mood (which i am fiddling with now) seem to fire at the beginning of an adventure, hence, adv=0 cannot work, but adv = 1 can.
 

Bale

Minion
The extra question is just my curiousity speaking, as the unconditional mood (which i am fiddling with now) seem to fire at the beginning of an adventure, hence, adv=0 cannot work, but adv = 1 can.

Moods fire before automatic adventuring or after relay adventuring. So, if you were adventuring in the relay browser your mileage would vary.

To call a script after automatic adventuring you need to use a betweenBattleScript which activates after adventures, but will not activate at all for relay adventuring.
 

Veracity

Developer
Staff member
Moods fire before automatic adventuring or after relay adventuring. So, if you were adventuring in the relay browser your mileage would vary.
That is very interesting. I seem to recall several threads pointing out this inconsistency before and suggestions - from you, even, if I recall correctly - suggesting that we normalize the behavior. Or, perhaps, it was some other kind of automated vs. Relay script inconsistency.

I have recently occasionally run with the "automatically maintain effects in the Relay Browser" preference. I never tried it before, since I wanted complete control of my MP and would therefore manually hit the up arrow on effects or click the "execute mood" link when my effects got low and I had enough MP.

I found the auto-mood refreshing to be convenient sometimes and *gasp* annoying other times. Sometimes I wanted to intentionally let such and such an effect to hit zero (so I could get maximum use out of it) before changing my mood or doing something like the hidden temple or a shore trip or turn-consuming crafting for which maintaining effects would be a waste of MP. To my *gasp* annoyance, because I had a mood active and the preference set, just when I was about to run out of an effect, KoLmafia would cast the skill and boost it again.

The point of running the mood BEFORE automating an adventure is to handle exactly that: you set a mood which says "before I adventure somewhere in which I might want an effect, make sure I have the effects I want". It will not execute your mood before a shore trip or crafting. It probably will execute it before the Hidden Temple - but considering wandering monsters, that might not be incorrect, although it's not something _I_ want.

I guess it's time to ask again: should we normalize mood execution for the GUI and the Relay Browser? I.e., do the mood check in the relay browser when you are about to hit adventure.php, say, rather than after you have finished such a visit?
 

Bale

Minion
It would break some things if moods were run before the turn instead of after. For example, I have a script that runs unconditionally as part of my mood. In this moodScript...

PHP:
if(item_amount($item[evil eye]) > 0) use(item_amount($item[evil eye]), $item[evil eye]);

That automatically uses my evil eyes as I gain them. If that was run before my turn instead of afterwards it may often take me one more turn to complete the Nook, unless I manually use the last evil eye. I added it to my moodScript so that I don't have to manually do something mindless and repetitive.

If you want to run moods before manually adventuring (which is a concept I approve of), then you should alter betweenBattleScripts to run after adventuring in the relay browser so that I can move my moodScript stuff to a betweenBattleScript and keep the functionality.

Moods should run before all adventures regardless of relay or automatic and betweenBattleScripts should run after all adventures regardless of relay or automatic. That would solve things nicely.


I found the auto-mood refreshing to be convenient sometimes and *gasp* annoying other times. Sometimes I wanted to intentionally let such and such an effect to hit zero (so I could get maximum use out of it) before changing my mood or doing something like the hidden temple or a shore trip or turn-consuming crafting for which maintaining effects would be a waste of MP. To my *gasp* annoyance, because I had a mood active and the preference set, just when I was about to run out of an effect, KoLmafia would cast the skill and boost it again.

This used to trouble me, but fortunately this has been made configurable by Jason. Now you can set any effect to burn down to 0 like Sonata by setting skillBurnXXXX = -100.

Often it is a very good thing that skills cast at 0 or else loss of Mojomelody would trouble me greatly. However it would probably be an improvement if the default was to recast at 0 like Sonata and make Mojomelody's casting at 1 the exception. Perhaps stat effecting buffs should be the only buffs to reeffect at 1 turn?
 
Last edited:

Veracity

Developer
Staff member
It would break some things if moods were run before the turn instead of after.
Were we to change this, do we change it early after a release - to allow people to change their scripts and for us to work out the issues - or just before a new release - which will surprise people who, for whatever reason, don't use daily builds? I suspect the former.

If you want to run moods before manually adventuring (which is a concept I approve of), then you should alter betweenBattleScripts to run after adventuring in the relay browser so that I can move my moodScript stuff to a betweenBattleScript and keep the functionality.

Moods should run before all adventures regardless of relay or automatic and betweenBattleScripts should run after all adventures regardless of relay or automatic. That would solve things nicely.
We currently have:

relayMaintainsEffects - Run moods during manual adventuring
relayMaintainsHealth - Maintain health during manual adventuring
relayMaintainsMana - Maintain mana during manual adventuring

I assume those last two invoke Recover Scripts, as needed. Presumably, we add

relayRunsBetweenBattleScripts

... and the set of four settings control how scripts/moods/autorecovery works in the Relay Browser.

Sounds like a good Feature Request.

Often it is a very good thing that skills cast at 0 or else loss of Mojomelody would trouble me greatly. However it would probably be an improvement if the default was to recast at 0 like Sonata and make Mojomelody's casting at 1 the exception. Perhaps stat effecting buffs should be the only buffs to reeffect at 1 turn?
Sounds like another Feature Request. Lets get more discussion in an official place - and maybe slyz or jason or somebody will take an interest. ;)
 
Thank you all for this interesting discussion.

IMHO, i do not see a need to change this method if it's going to break some scripts.
Just mentioning this in a seperate page in the wiki (which, searching 'moods' in mafia wiki gives me a redirect to 'KoLmafia Guide: Setting Preferences') will do, or even Bale's answer, pasted somewhere, might be sufficient. The difference between relay and automatic is a mere 1 adventure after all (to me that is, any discussion about how valuable 1 adventure is should NOT come here. Thanks!).
This is my opinion as a KOLmafia user for the past 5 years (GASP!) and not as a scripter.

Once again, THANK YOU for this awesome program. :D
 
Top