chatbotScript and logic flow

Once before I had an issue with chatbotScripts where in print(constant string) would actually print... well, something different than the constant, due to an unrelated error prior.

Now, however, I'm getting very very interesting things.

Code:
string[int] relaybot;
string my_clan = "Ataraxia";

relaybot[1] = "MesaChat";
relaybot[2] = "ToTChat";

int ml_level()
{
	string hhlog = visit_url("clan_raidlogs.php");
//Does this get called every time? Print function next to test.
	print(substring(hhlog,0,10));
	int ml = 0;
	matcher ml1 = create_matcher("",hhlog);
	matcher ml2 = create_matcher("",hhlog);
	matcher ml3 = create_matcher("",hhlog);
	while (find(ml1) || find(ml2) || find(ml3))
		ml+=1;
	matcher ml4 = create_matcher("",hhlog);
	matcher ml5 = create_matcher("",hhlog);
	matcher ml6 = create_matcher("",hhlog);
	if (find(ml4) || find(ml5) || find(ml6))
		ml-=1;
	return ml;
}

void main(string sender,string message,string channel)
{
	if (sender == "System Message")
		return;
	if (sender == my_name())
		return;
	foreach i in relaybot
		if (sender == relaybot[i])
		{
			if (message == "retrieve ml level")
			{
				chat_private(relaybot[i],my_clan + "is at ML level " + ml_level() + ".");
				return;
			}
			chat_clan(message);
		}
	if (channel == "/clan" || channel == "/hauntedhouse")
	{
		if (message == "ml?")
		{
			chat_clan("ML is at level " + ml_level() + ".");
			return;
		}
		string bot_send;
		if ((length(message) > 4) && (substring(message,0,length(message)-4) == " ml?"))
		{
			string clan_match = substring(message,length(message)-4);
			if (clan_match == "mesa")
				bot_send = "MesaChat";
			if (clan_match == "tot")
				bot_send = "ToTChat";
			if (clan_match == "ax" || clan_match == "ataraxia" || clan_match == "atar")
				bot_send = "AxChat";
			chat_private(bot_send,"retrieve ml level");
			return;
		}
		if (message == "who's in tot?")
		{
			chat_private("ToTChat","retrieve who list");
			return;
		}
		if (message == "who's in ax?" || message == "who's in atar?" || message == "who's in ataraxia?")
		{
			chat_private("AxChat","retrieve who list");
			return;
		}
		foreach i in relaybot
			chat_private(relaybot[i],sender + ": " + message);
	}
}

I get some very... schrodinger-esque mechanics here. If I put some print statements around the first block regarding (sender==my_name()) then it appears to exit just fine: only the first print statement executes.

If, however, I remove that and stick a if(sender==my_name()) print( "INDIAN MAGIC!"); just before the very last foreach statement, well... INDIAN MAGIC!
I've looked over and over and I don't understand at all how it could -not- return at the start, but (sender==my_name()) is true later, when no statement in between changes either of the values.

Background: I have a few accounts all running nearly-identical value (differing string constants, obviously) and during preliminary testing they would... run an endless echo like such:
Code:
Player: Hello.
Bot1: Bot 2: Player: Hello.
Bot1: Bot 2: Bot 1: Bot 2: Player: Hello.
...
I can easily fix this (instead of printing Indian Magic I just return...) but what I don't understand is why the -first- name-equals-me-return statement is... skipped. But only if I'm not looking.

Using: r9913, windows 7
 
Last edited:
Case sensitivity?

string == string isn't case sensitive. And even if it were, (sender==my_name()) should either be true everywhere or false everywhere.

I have a feeling that the recent changes to KoL's chat system may be having ... weird side-effects on mafia. My other bots that normally work fine suddenly hang for no reason.
 

holatuwol

Developer
Hm, forgot about case insensitivity.

So you're also saying, if you print out sender and my_name() to try to debug the problem, you never run into it?
 
Hm, forgot about case insensitivity.

So you're also saying, if you print out sender and my_name() to try to debug the problem, you never run into it?

I'm not sure about never, and that's not what I'm printing.
basically, I do
Code:
 print(1);
 if (sender==my_name()) return;
 print(2);

And in testing print(2) never happens...
But without the prints, the bot definitely resumes and acts on his code, as later down the line he sends "My Name: Someone Else: Statement" when the code should have never made it that far.

I'm not too worried about it, as the bot works as desired, just curious as to how the Indian Magic line occurs, since there should be zero circumstances under which it activates.
 
Top