matcher issue

Pazleysox

Member
Why does this fail:
Code:
void main()
{
	string thesea = visit_url("main.php");
	matcher need = create_matcher( "title=\"(\w+) (\w+)" , thesea );
		{
		need.find();
		string group1= need.group( 1 );
			{
			print(group1);
			}
		}
}
and this works:
Code:
	string CheckGrinderNext= visit_url( "inventory.php?action=grind" );
	matcher need = create_matcher( "needs (\\d+)" , CheckGrinderNext );
			{
			need.find();
			string group1= need.group( 1 );
				{
				if ((group1) >= 1)
					{
					print("You need to grind more stuff to make sausage", "red");
					}
				}
			}
 

xKiv

Active member
Code:
(\w+) (\w+)"
Perhaps start by escaping those backslashes?
(they are escaped in the "(\\d+)" example that works).
 

Crowther

Active member
I'm sorry my original post didn't have the \\. It IS in the script, and still didn't work.
When I fixed the \ vs \\ issue, your script "worked" for me. In that it matched something. It printed "Fight". Without your actual code, it is hard for people to help you.
Code:
void main()
{
        string thesea = visit_url("main.php");
        matcher need = create_matcher( "title=\"(\\w+) (\\w+)" , thesea );
                {
                need.find();
                string group1= need.group( 1 );
                        {
                        print(group1);
                        }
                }
}
 

Pazleysox

Member
When I fixed the \ vs \\ issue, your script "worked" for me. In that it matched something. It printed "Fight". Without your actual code, it is hard for people to help you.

I looked again, and I had missed the second \. I really thought I had fixed that. I did find the information I was looking for. Mafia will not allow you to create a matcher when mall.php is in the url.

I was doing this:
Code:
buffer checkmall = visit_url("main.php");
//	buffer checkmall = visit_url("mall.php");
	matcher have = create_matcher( "(\\w+)" , checkmall );
		{
		have.find();
		string group1= have.group( 1 );
			{
			print(group1);
			}
		}
"html" was the output. It mattered not what it was, I just needed it to work.
Code:
//buffer checkmall = visit_url("main.php");
buffer checkmall = visit_url("mall.php");
	matcher have = create_matcher( "(\\w+)" , checkmall );

		{
		have.find();
		string group1= have.group( 1 );
			{
			print(group1);
			}
		}
No match attempted or previous match failed (00TEST - Copy.ash, line 8)
at main (00TEST - Copy.ash:8)
was my output. Unless I really screwed something up, the only thing I can think of is what I said above.

Thank you Crowther for looking into this for me.
 

Pazleysox

Member
Code:
void main(){
	string Pooltable= visit_url( "clan_viplounge.php?action=pooltable&whichfloor=2" );
	matcher n_stash_put = create_matcher( "clanmate (\\w+)" , Pooltable );
	int J=0;
	while( J<1 )
		{
		n_stash_put.find();
		J=J+1;
		string group1= n_stash_put.group( 1 );
                print(group1 + " is currently on the table");
		}
}
This works just fine on my computer.

When I swap it to a different computer changing nothing at all and it fails.
I get this error:
No match attempted or previous match failed (pool.ash, line 9)
at main (pool.ash:9)
Line 9: string group1= n_stash_put.group( 1 );

I wrote a matcher that was looked at the whole line. For example:
Looks like your clanmate Ruby is in charge of the table, having won the last 60 games in a row.
with this code:
create_matcher( "clanmate (\\w+) is in charge of the table(\\D) having won the last (\\d+)" , Pooltable );
Which failed. If I take the (\\d+) off, it works. If I try using anything in front of the (\\d+) it fails.

I can't get create_matcher( "last (\\d+) games"), Pooltable ) to work. If I leave even 1 letter in LAST, it fails.
create_matcher( "(\\d+) games"), Pooltable ) DOES work.

I use about 10 matchers in various scripts that I run, that work just fine. I spent a while working on this today to try and pinpoint where it was going to fail on my computer. Once I got a working copy, I sent it to another computer, and it failed there each time. Both were running build 19136.

Is it something I'm doing wrong? I know there's another way to write a matcher. I have not at this moment attempted it. I will tomorrow, when I'm back at the console.
 
Last edited:

fronobulax

Developer
Staff member
Are both computers running the same operating system?

Are all of the KoLmafia files and settings reasonably close to the same on both systems? (Ideally the KoLmafia directory was copied from one to the other).

Is the response from visit_url identical? If you are not using the same character in the same clan on both machines I would wonder if that was an issue?

Are both machines running the same version of Java?

I freely admit to lacking in imagination but most of the things I can think of deal with the hypothesis that the computers are not identical when it comes to characters and character sets.
 

Pazleysox

Member
Are both computers running the same operating system?

Are all of the KoLmafia files and settings reasonably close to the same on both systems? (Ideally the KoLmafia directory was copied from one to the other).

Is the response from visit_url identical? If you are not using the same character in the same clan on both machines I would wonder if that was an issue?

Are both machines running the same version of Java?

I freely admit to lacking in imagination but most of the things I can think of deal with the hypothesis that the computers are not identical when it comes to characters and character sets.

They are both running windows 10. The KoLmafia files and settings are very reasonably close.

The response from visit_url is identical. They are separate characters in the same clan.

Java... I do not know. I will look into this.

Even if the computers weren't identical I had some of the issues on the machine I use all the time. (The one I am currently on)
I had trouble with this: create_matcher( "last (\\d+) games")
Which in theory should have worked. When I was working on the script today. I keep getting an error. When I finally worked around the issue, I finished the script, and had it working on this machine, only to have it fail on the other.

The matcher seemed to fail anytime I had anything in front of the (\\d+), seemingly regardless of putting words behind it.

Just to see if it was a KOL issue, I tried this:
last(\\D)(\\d+), and
last(\\D) (\\d+), and multiple variations, to no avail.

Oh yes, I'm running Java v8 update 201 (build 1.8.0_201-b09) I will check the other machine tomorrow.
 

heeheehee

Developer
Staff member
KoL has very inconsistent formatting. If you look at the HTML, you'll see:

Code:
Looks like your clanmate Plater is in charge of the table, having won the last  17114 games in a row.

Namely, there are two spaces after "last".

Code:
"clanmate (\\w+) is in charge of the table, having won the last  (\\d+)"
should match this particular case, although that will break if a playername containing spaces is on top of the table. I'd suggest using something like
Code:
[a-zA-Z0-9_ ]+
or just
Code:
[\\w ]+
(note the space in each of these)


Unrelated, a more typical way of writing this code would be:

Code:
void main(){
  string Pooltable= visit_url( "clan_viplounge.php?action=pooltable&whichfloor=2" );
  matcher n_stash_put = create_matcher( "clanmate (\\w+) is in charge of the table, having won the last  (\\d+)" , Pooltable );
  if ( n_stash_put.find() )
  {
    string group1= n_stash_put.group( 1 );
    print(group1 + " is currently on the table");
  }
}

since find(matcher) returns a boolean, and will cause your script to abort if you attempt to use group(matcher) even though the match failed.
 

heeheehee

Developer
Staff member
I don't have an answer as to why running the same script on two different characters / machines would yield different results. As frono implies, \w matches a "word" character, which may differ depending on your language settings. I don't think anything else in this script should vary by Java version or OS; if it does, file a bug.
 

fronobulax

Developer
Staff member
I don't have an answer as to why running the same script on two different characters / machines would yield different results. As frono implies, \w matches a "word" character, which may differ depending on your language settings. I don't think anything else in this script should vary by Java version or OS; if it does, file a bug.

I asked because in Ye Olden Days I had code that did not work because of things like: different default charsets; different case sensitivities; Java system properties; and so on. Asking the questions is my knee jerk reaction to "it works on one computer but not the other".

As a debugging hint, I would consider getting the url string, doing a global subsitiution of underbar ("_") for space and then trying the matcher. That will highlight the cases where KoL is not consistent in the use of whitespace.
 

Pazleysox

Member
Namely, there are two spaces after "last".

Code:
"clanmate (\\w+) is in charge of the table, having won the last  (\\d+)"
should match this particular case, although that will break if a playername containing spaces is on top of the table. I'd suggest using something like
Code:
[a-zA-Z0-9_ ]+
or just
Code:
[\\w ]+
(note the space in each of these)

The 2 spaces was doing me in. I never would have thought of that!

Here's what I ended up putting.
Code:
	matcher n_stash_put = create_matcher( "clanmate ([\\w\\s]+) is in charge of the table, having won the last  (\\d+)" , PVPHill );

I use the ([\\w\\s]+) on a different script, which has never given me issues. And now that I'm looking at that, I can fix a different script that was giving me grief too.

Thanks for your help. Much appreciated!
 

Pazleysox

Member
So here's some interesting information.
I upgraded Java this morning, because the script failed on the other computer.

The script works for me, but there's something strange going on. I was on the computer that was having an issue. I ended up putting my settings folder, and a copy of build 19136, in a separate folder. Opened a "new" instance mafia, ran script, no problem, worked perfect. Logged out of my account, and logged into my multi account (to create a brand new settings file), without closing the mafia login window. Ran script, and it failed.


On my main computer: I opened the mafia that I use all the time.

I logged on another existing multi, one which had settings already on the computer, and ran into the same issue.

I even copy/pasted/renamed my "pazsox_prefs" file into the multi's name, and the script failed.
 

heeheehee

Developer
Staff member
To confirm, your multi has a VIP key and isn't in a path with Standard restrictions?

i.e. can you access the pool table in the relay browser? Does the visit_url contain the HTML on your multi as expected? Sounds like the problem is tied to the account, not the script.
 

Pazleysox

Member
To confirm, your multi has a VIP key and isn't in a path with Standard restrictions?

i.e. can you access the pool table in the relay browser? Does the visit_url contain the HTML on your multi as expected? Sounds like the problem is tied to the account, not the script.

This is all correct. The multi I wrote this script for is not under standard restrictions, and does in fact have the VIP key. They actually have control of the table also. Which is why I'm so confused.
 

Pazleysox

Member
I found the problem.

Here's what you see when you are in charge of the table:

Looks like you're in charge of the table, having won the last 113 games in a row.

Here's what everyone else sees:
Looks like your clanmate Ruby is in charge of the table, having won the last 113 games in a row.

Makes sense now that the matcher would fail. The text is completely different. I can't believe I didn't think of this. Sorry for causing so much trouble.
 

Pazleysox

Member
Sounds like the problem is tied to the account, not the script.

That is absolutely correct.

Here's my work around. Seems so simple, I feel kind of dumb for not thinking of this sooner.

Code:
	string Pooltable= visit_url( "clan_viplounge.php?action=pooltable&whichfloor=2" );
	if ((my_name() == "ruby") && Pooltable.contains_text("showplayer.php?who=599575"))
		{
		matcher n_stash_put = create_matcher( "Looks like you're in charge of the table, having won the last  (\\d+)" , Pooltable );
		}
	if ((my_name() != "ruby") && Pooltable.contains_text("showplayer.php?who=599575"))
		{
		matcher o_stash_put = create_matcher( "clanmate ([\\w\\s]+) is in charge of the table, having won the last  (\\d+)" , Pooltable );
		}
	if (!Pooltable.contains_text("showplayer.php?who=599575"))
		{
		matcher o_stash_put = create_matcher( "clanmate ([\\w\\s]+) is in charge of the table, having won the last  (\\d+)" , Pooltable );
		}
Now the script will look at the table, and only print out whats relevant, regardless of the account I'm using. I've run this, and it does work. Thank you for your help. I greatly appreciate it.
 
Last edited:

heeheehee

Developer
Staff member
FYI you can use a matcher with alternation to handle both of these cases, e.g. something like
Code:
"Looks like (you're|your clanmate (.*?) is) in charge of the table, having won the last  (\\d+) games in a row"
...
if (m.group(1) == "you're") {
  player = my_name();
} else {
  player = m.group(2);
}
 

Pazleysox

Member
I think I found a bug? I was working with an existing matcher today, and it failed, where it had never failed before. The matcher is supposed to pull a players clan name from their character sheet. I spent some time mulling over it, and trying to work out why it failed. I could get it to work on some characters, and then one in perticular it wouldn't work.

The character it would fail on had a space in their name, so I looked at other players with a space, and it worked fine.

I finally figured out that the character in question has 0 permanent skills. So I looked around, and I found #13 (Mr. Skullhead), who fit the bill. Space in his name, no permanent skills, and the script failed on him also. It worked on every other account that I tested that has permanent Skills. I could not find a player who PVP's, and has not ascended. Not to say one doesn't exist, just that I have not found one as of this post.

Code:
void main()
{
	string whowho = visit_url( "showplayer.php?who=" + get_player_id( spaz ox ) );
	matcher classy = create_matcher("whichclan=(\\d+)\">([^<]+)", whowho);
	if(find(classy)) 
	{
	set_property("_classy2", classy.group(2)); // set name of clan player PVP's for
 	int I=0;
while( I<1 )
{
classy.find();
I=I+1;
string group1= classy.group( 1 );
string group2= classy.group( 2 );


	if(get_property("_classy2") != group2) // Look at a players PVP clan, if different, don't use it.  The matcher will actually pick up both.
		set_property("_classy2", group2); // this is the clan the player is in when the script is run.

	print("Player: " + get_property("_sender") + ", Clan: " + get_property("_classy2"));
}}}

For the time being, I'm putting in a check for permanent skills, and if the words aren't found, the script will return that information.
 
Top