Is there a better way to get the value for a counter

ElCarrot

New member
I've been messing around with the counter scripts trying to get around one issue and so far had no luck. The main issue is that if I am on a bounty hunt and the fortune cookie counterscript triggers, sometimes when it gets back from obtaining the semi-rare, the goals will have been cleared, so my bounty script just keeps plugging away at the bounty location - even though the lucre has already been obtained. This tends to occur when the turn on which the final bounty item is obtained / would be obtained falls exactly on the same turn that the fortune cookie counter is up. (I can't reproduce this with any consistency unfortunately - but it gets annoying when it does happen)

So to get around that, I decided to try manually obtaining the count till the next fortune cookie number and handle it inside the bounty script.

e.g.
Next Cookie number is 56, so adventure 55 turns, and then spend 1 turn at the desired semi-rare location. Then add the bounty goal back in and continue.

The code I use to get the exact value of the counter is this:

Code:
// return next semi-rare value or -1 if there is no next value
int getNextSemiAdv() {
	String checkRare;
	
	// To save processing time - do an overall check first
	if (get_counters("Fortune Cookie", 0, my_adventures()) == "") {
		return -1;
	}
	
	// One does exist - so iterate to find the number
	for i from 0 upto my_adventures() {
		if (get_counters("Fortune Cookie", i, i) != "") {
			return i;
		}
	}
	return -1;
}

As you can see - this code is rather ugly - but it works. What I'm hoping is that there is a better way to do this - that is - to get the specific value of a certain counter without having to loop through each number.

Any suggestions?
 

ElCarrot

New member
Well - the scripts in the linked post *were* working for a while - until I moved to version 13.7 - at which point they all stopped working - so I'm back to using the code I posted originally.

However, I have a second question which is linked in with the first (And it's probably something really simple which I'm not seeing) - when the turn rolls around to go and get the semi-rare - I get interrupted by the "fortune cookie counter has expired" message. It blocks my attempt to adventure in my target location and stops the script from executing.

I've tried setting the counterscript variable to blank - but it still happens - any suggestions? (Do I have to return a value from the "adventure" call?)

Thanks
 

Bale

Minion
Scripts stop executing when a counter expires. That's what they're for. It is a feature, not a bug. This is what happens when you don't have a counterScript. The best way to ignore the counters is just to avoid eating fortune cookies. Mafia assumes that if you eat the cookie, you want the semi-rare and stops adventuring when it comes up.

To cause scripts to ignore the expiration of a counter you'll need a counterScript that does nothing.

It's also possible that you can ignore the counter by having a script that does (!adventure(turns, locale)); though I haven't tested that.
 
Last edited:

ElCarrot

New member
Well - I was able to get around it by just having it return a value

e.g.
boolean dotest = adventure(bounty_adv+1, currentBounty.bountyLocation);

The problem then is that it also will not terminate when it finishes the bounty hunt. It will just keep on going for however many adventures are specified.

So I'm back to using regular counterscripts and hoping that the intermittent issue I encountered doesn't happen too much.

Thanks for the help though
 
Top