Question about get_counters

Banana Lord

Member
Code:
get_counters("fortune", 0, 300)

Returns "Fortune Cookie" if I have an active semi-rare counter, and "" if I don't. So far so good. What happens when I have more than one active semi-rare counters (as generated by eating a single cookie)?
 

Banana Lord

Member
Yeah, I saw that. But I read it as referring to multiple different counters, rather than multiple identical ones. Is that not the case?
 

Banana Lord

Member
Oh OK. Hmmm. Any good ideas for how I could modify the code below to take that into account?

Code:
if(get_counters("fortune", 0, 300) != "Fortune Cookie") 
	{
	if(item_amount($item[fortune cookie]) == 0) buy(1, $item[fortune cookie]);
	eat_silent(1, $item[fortune cookie]);
	}

And as a side note, what's wrong with my use of eat_silent? I keep getting function undefined errors.
 

heeheehee

Developer
Staff member
PHP:
if(!get_counters("fortune", 0, 300).contains_text("Fortune Cookie"))
    {
    // blah blah blah
    }
eatsilent() shouldn't be giving you errors unless you're using a horribly outdated version of Mafia (read: older than version 13.9 / r8048).
 

Banana Lord

Member
Aha! I was just about to post this:

PHP:
if(get_counters("fortune", 0, 300) == "") 
	{
	if(item_amount($item[fortune cookie]) == 0) buy(1, $item[fortune cookie]);
	eat_silent(1, $item[fortune cookie]);
	}

So from a purely academic point of view, would my way work too?

EDIT: Oh no, of course it wouldn't. Well, only if I didn't have any other counters running.

Well that's what I would've thought, but I'm using r8427. Is it eat_silent(), or eatsilent()? Do I need a cookie in my inventory to avoid an error? I haven't run that code yet (so I don't have one floating around at the moment), but eat() doesn't require the item to be present, it just tells you that you need 1 more <item> to continue, so I assumed that eat_silent() would behave in the same way.
 
Last edited:

tgetgel

Member
So, how would I modify this to not eat a fortune cookie if only one value was returned?
Eat if ""
Eat if multiple values
Don't eat if only one non-zero value returned
 

slyz

Developer
PHP:
string counters = get_counters("fortune",0,300);
if ( index_of(counters,"fortune") == -1 || index_of(counters,"fortune") != last_index_of(counters,"fortune") )
{
    retrieve_item(1, $item[fortune cookie]);
    eatsilent(1, $item[fortune cookie]);
}
 
Top