Parsing get_property of relayCounters

natnit

Member
Hey folks. I've been playing with Bale's CC script, and was trying to generalize a way to find out on which adventure the next SR should be coming up. I apologize for the poor coding style (and variable names :()...it's been a long time since I've written anything.

Code:
int nextSR(string S) {
	string counter_string = get_property("relayCounters");
	if(!contains_text(counter_string,S)
		return -1;
	int x = index_of(counter_string,S);
	int adv_of_sr = substring(counter_string,0,x).to_int();
	return adv_of_sr;
}

Of course, this only works if I only have 1 counter (the fortune cookie counter, in this case), or if it is the first in the series of counters. Would anyone please help me generalize this into the scenario where multiple counters might exist, if only for robustness? :)

Thanks!
 

jasonharper

Developer
Do you really need to know the exact turn of the next expected semi-rare, or would simply knowing whether or not it's in a given range be sufficient? The latter can be done easily:
get_counters("Fortune Cookie", 0, 10) != ""
will be true if one is expected within the next 10 turns, for example.

If you must parse relayCounters, the proper way to do so would be to split it on colons using split_string(), and treat the split pieces in groups of three - they'll be the turn number, counter name, and image filename.
 

natnit

Member
Thanks Jason! With your help, I was able to piece something together that worked. To be honest, if I thought around the problem, I wouldn't really have to pinpoint the exact value of the SR adventure, but I just wasn't feeling creative.

And just in case it helps anyone else:

Code:
// In main code, to check if cookie counter has been set
if (get_counters("Fortune Cookie", 0, 200) == "") {
	eat(1, $item[fortune cookie]);
}

Code:
// Once you've checked that there's a counter set
int nextSR() {
	string [int] S = split_string(get_property("relayCounters"),":");
	
	foreach i in S {
		if (i%3 == 1)
			if (S[i] == "Fortune Cookie")
				return S[i-1].to_int();
	}
	return -1;
}

Thanks again!
 
Top