Feature Run counter script in relay?

Razorsoup

Member
While adventuring using the relay browser, KoLmafia will warn me when a fortune cookie counter is expiring. Is there an option to have KoLmafia automatically run my counter script at that time similar to the option for the before and after battle scripts? I am using Bale's CounterChecker as my counter script.
 

Winterbay

Active member
I don't think so, but nothings stops you from having you betweenbattle or beforebattle scripts vall the counter checker I guess...
 

Razorsoup

Member
I don't think so, but nothings stops you from having you betweenbattle or beforebattle scripts vall the counter checker I guess...

Well, nothing except a lack of skill. I'll have to decide if those semi-rares are worth the effort of figuring out how exactly to do this and have it play nicely with BestBetweenBattle.ash. Thank you for the suggestion.
 

Bale

Minion
nothing stops you from having your betweenbattle or beforebattle scripts call the counter checker

It's actually a bit tricky to do this. Winterbay is bullying Razoroup by tossing it out as if this was no big deal.

Unlike some other triggered scripts, a counter script is called with the name of the counter and the number of turns left. That means a script which calls the counter script will need to acquire that information to pass on to the counterScript. I can get the name of all coming counters with get_counters("Fortune Cookie", 0, 200), but that won't tell me how many turns are left. I suppose I can narrow it down to the counters that are going to be up right now by using get_counters("Fortune Cookie", 0, 0), but what if the player is adventuring in the shore or underwater? In those cases we'd need to know about the next 2 or 3 turns.

This is a non-trivial exercise and I'm not entirely certain how to solve it, so I certainly wouldn't expect Razorsoup to know the answer. Perhaps Winterbay could explain his solution so that Razorsoup and I both could learn from him.
 
Last edited:

Winterbay

Active member
Well... I can't. I was thinking on getting when the counter was at 0 and then calling the counterscript, so I guess that means that you need to import the counterchecker into the betweenbattlescript. I did not think of any underwater or shore complications :)
 

Bale

Minion
And crafting! There is also a counter warning if crafting takes 1 or more turns. A before or after battle script won't run at that time.

What I'm getting at is that Razorsoup's feature request would be helpful and very difficult to script.

Just give an icon to click on if the user has assigned a value to counterScript.
 
Last edited:

Fluxxdog

Active member
Bale is right. It is non-trivial. I've found a rather acceptable workaround with this:
Code:
int countdown(string counter){
	for x from 0 to 1000 if(get_counters(counter,x,x)==counter) return x;
	return -1;
}
...but if there are any counters that are longer than 1000, it'll return -1. This is unlikely, but there needs to be some kind of upper limit. Since I use it for part of calculating semirare probabilities, 1000 was the highest I was willing to let it go. A better solution would be to get an array of current counters. Maybe a FReq to overload get_counters with a no argument version that return a int[string] array.

Hey! Guess what I'm doing?
 

Razorsoup

Member
And crafting! There is also a counter warning if crafting takes 1 or more turns. A before or after battle script won't run at that time.

What I'm getting at is that Razorsoup's feature request would be helpful and very difficult to script.

Just give an icon to click on if the user has assigned a value to counterScript.

I'm beginning to understand why this wasn't already a standard feature of KoLmafia. Based on Winterbay's suggestion, the best I could come up with was this for a before battle script:
Code:
import <CounterChecker.ash>;

void main() {
	string fortuneCounter = get_counters("Fortune Cookie", 0, 0);
	if (fortuneCounter != "") {
		get_semirare();
	}
	cli_execute("BestBetweenBattle.ash");
}

I never actually tested it so there is probably typos or other errors. Would that (or something similar) have even worked? Granted, even if this did work it would only work for semi-rares and not any of the other things CounterChecker.ash does so it still wouldn't be optimal.
 
Last edited:

Bale

Minion
I just moved this thread to the bug reports forum as a feature request. Because I think it would be a nice feature and deserves to be considered as such.

Please carry on with discussion of how to implemented it as a script. That might be all the solution we get.
 
Top