Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 23

Thread: matcher issue

  1. #1
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    465

    Default matcher issue

    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");
    					}
    				}
    			}
    Scripts I have written:
    Unlock Dread A Script to save you a bunch of clicks.
    Standard Rollover Bonus A Script that shows best items to pull/equip for bonus turns.
    Standard PVP Bonus A Script that shows the best items to pull/equip for bonus PVP Fights.
    Rollover Management A Script that does all the daily deeds you might have forgotten, or might have missed.
    Chatbot A Chatbot script. Simple start for those who want/need one for their clan.
    Zap Wand A Dungeon of Doom ZAP WAND getting script.

  2. #2
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,834

    Default

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

  3. #3
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    465

    Default

    I'm sorry my original post didn't have the \\. It IS in the script, and still didn't work.

  4. #4
    Senior Member Crowther's Avatar
    Join Date
    Nov 2006
    Posts
    1,468

    Default

    I'm sorry my original post didn't have the \\. It IS in the script, and still didn't work.
    Originally Posted by Pazleysox View Post
    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);
                            }
                    }
    }

  5. #5
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    465

    Default

    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.
    Originally Posted by Crowther View Post
    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.
    Scripts I have written:
    Unlock Dread A Script to save you a bunch of clicks.
    Standard Rollover Bonus A Script that shows best items to pull/equip for bonus turns.
    Standard PVP Bonus A Script that shows the best items to pull/equip for bonus PVP Fights.
    Rollover Management A Script that does all the daily deeds you might have forgotten, or might have missed.
    Chatbot A Chatbot script. Simple start for those who want/need one for their clan.
    Zap Wand A Dungeon of Doom ZAP WAND getting script.

  6. #6
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    465

    Default

    This post said the mall is not directly accessible. 5 years ago.

  7. #7
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    465

    Default

    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 by Pazleysox; 03-20-2019 at 06:08 PM.

  8. #8
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,356

    Default

    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.

  9. #9
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    465

    Default

    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.
    Originally Posted by fronobulax View Post
    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.
    Scripts I have written:
    Unlock Dread A Script to save you a bunch of clicks.
    Standard Rollover Bonus A Script that shows best items to pull/equip for bonus turns.
    Standard PVP Bonus A Script that shows the best items to pull/equip for bonus PVP Fights.
    Rollover Management A Script that does all the daily deeds you might have forgotten, or might have missed.
    Chatbot A Chatbot script. Simple start for those who want/need one for their clan.
    Zap Wand A Dungeon of Doom ZAP WAND getting script.

  10. #10
    Developer
    Join Date
    Aug 2009
    Posts
    2,922

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •